PDA

View Full Version : urgent help reqd



sukanya.paul
05-31-2007, 06:38 AM
hi i am displayin records from my mysql database but i want then to be displayed pagewise..can some1 help..please please please..

my code so far:
<?php
include 'db.php';
$valid = false;
$jobcode=$_POST['jobcode'];
$sql="SELECT job.jobcode,job.subject,job.description,job.opening,job.postdate,job.lastdate,candidate.candidate_id,candidate.firstname,candidate.lastname,candidate.resume FROM candidate,job WHERE candidate.jobcode ='$jobcode' AND job.jobcode='$jobcode'";

$query = mysql_query($sql) or die (mysql_error());
$count=mysql_num_rows($query);
if ($count>0)
$valid=true;
if ($valid)
{
echo "<table width='95&#37;' border='2' >
<tr>
<th>JOB CODE</th>
<th>JOB SUBJECT</th>
<th>JOB DESCRIPTION</th>
<th>NUMBER OF OPENINGS</th>
<th>POST DATE</th>
<th>LAST DATE</th>
<th>CANDIDATE ID</th>
<th>FIRST NAME</th>
<th>LAST NAME</th>
<th>RESUME</th>
</tr>";
while($row = mysql_fetch_array($query))
{
echo "<tr>";
echo "<td>" . $row['jobcode'] . "</td>";
echo "<td>" . $row['subject'] . "</td>";
echo "<td>" . $row['description'] . "</td>";
echo "<td>" . $row['opening'] . "</td>";
echo "<td>" .$row['postdate'] . "</td>";
echo "<td>" . $row['lastdate'] . "</td>";
echo "<td>" .$row['candidate_id'] . "</td>";
echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['lastname'] . "</td>";
echo("<td>");
echo("<a href='" . $row['resume'] . " ' target = '_blank' >" );
echo("<br/>" . $row['resume'] . "</a>");
echo("</td>");
echo "</tr>";
}
echo "</table>";
}
else
echo "<BR><center> NO PROFILES MATCH THE CRITERIA GIVEN.</CENTER> ";

?>
this works fine but not pagewise

tech_support
05-31-2007, 06:53 AM
Please don't use non-descriptive/meaningless titles.
Putting urgent in the title won't make time go faster also.

sukanya.paul
05-31-2007, 06:57 AM
sorry abt non descriptive title but thts the only one i cud cm up with and u have "not" told me not to use urgent.i was expecting a reply not this..
thanks anyways

tech_support
05-31-2007, 07:00 AM
Sorry, I got messed up with you and another person :p

About your problem... What do you mean by "pagewise"?
Splitting your query to several pages?

sukanya.paul
05-31-2007, 07:12 AM
ya i want to display only 10 records in a single page...

mburt
06-01-2007, 12:08 AM
Maybe doing this manually (if statements) would be the best thing. Trying to apply that to the code supplied and that extremely long MySql query could be hard.

mbrodin
06-01-2007, 11:10 AM
Good day, Sukanya.paul!

I took my time and coded what I think you may want!

You can edit variable $paginLimit, this tells the function to show, if you are on page 8 of maybe 67 pages, it shows, << Prev - ... 4 5 6 7 8 9 10 11 12 13 ... - Next >>, I also added links to first page and last page for You!


<?php

// Include DB.php
include 'db.php';

function mkPagination($start, $max, $total, $pgLimit)
{

GLOBAL $jobcode;

$page_req = $_SERVER["SCRIPT_NAME"];

$showPrev = false;
$showNext = false;

$stringHTML = "";

$tPages = round( $total / $max );

// If more then One page!
if( $tPages > 1 )
{

if( $start > $total )
{
$start = $total;
}

// The current page ...
$cPage = ( floor( $start / $max ) + 1 );

if( $cPage < 1 )
{
$cPage = 1;
}
elseif( $cPage > 1 )
{
$show_prev = true;
}

if( $cPage > $tPages )
{
$cPage = $tPages;
}

if( $cPage < $tPages )
{
$show_next = true;
}

// Show Prev link
if( $show_prev == true )
{
$prevHTML = "<a href=\"" . $page_req . "?jobcode=" . $jobcode . "&start=" . ( $cPage * $max - ( $max * 2 ) ) . "\"><< Prev</a> | ";
}

// Show Next link
if( $show_next == true )
{
$nextHTML = " | <a href=\"" . $page_req . "?jobcode=" . $jobcode . "&start=" . ( ( $start < 1 ? 0 : $start ) + $max ) . "\">Next >></a>";
}

if( $tPages > 1 )
{

$startLink = ( $cPage - $pgLimit );

if( $startLink < 1 )
{
$startLink = 1;
}
elseif( $startLink > $tPages )
{
$startLink = ( $tPages - 1 );
}

$stopLink = ( $cPage + $pgLimit );

if( $stopLink > $tPages )
{
$stopLink = $tPages;
}

}
else
{
$startLink = 1;
$stopLink = $tPages;
}

if( $startLink > 1 )
{
$firstHTML = "<a href=\"" . $page_req . "?jobcode=" . $jobcode . "&start=0\"><< First page</a> - ";
$strHTML .= "...";
}

for( $i = $startLink; $i < ( $stopLink + 1 ); $i++ )
{

if( $i == $cPage )
{
$strHTML .= " <strong>" . $i . "</strong> ";
}
else
{
$strHTML .= " <a href=\"" . $page_req . "?jobcode=" . $jobcode . "&start=" . ( ( $i * $max ) - $max ) . "\">" . $i . "</a> ";
}

}

if( $stopLink < $tPages )
{
$strHTML .= "...";
$lastHTML = " - <a href=\"" . $page_req . "?jobcode=" . $jobcode . "&start=" . ( ( $tPages * $max ) - $max ) . "\">Last page >></a>";
}

return $firstHTML . $prevHTML . $strHTML . $nextHTML . $lastHTML;
}

return "";
}


// -------------------------------------------------------------------


// How many pages before and after the current page.
$paginLimit = 4;

$jobcode = $_REQUEST['jobcode'];

// Start of the SQL-query ...
$start = ( $_REQUEST['start'] > 0 ? $_REQUEST['start'] : 0 );
$max = ( $_REQUEST['max'] < 10 ? 10 : $_REQUEST['max'] );

$isValid = false;


$sql = "SELECT
job.jobcode,
job.subject,
job.description,
job.opening,
job.postdate,
job.lastdate,
candidate.candidate_id,
candidate.firstname,
candidate.lastname,
candidate.resume

FROM

candidate,
job

WHERE

candidate.jobcode = '" . $jobcode . "'

AND

job.jobcode = '" . $jobcode . "'";

$query_num = mysql_query($sql) or die (mysql_error());

$total = mysql_num_rows( $query_num );

if( $total > 0 )
{

// If ( $start + $max ) is more than $total, $start = ( $total - $max )
if( ( $start + $max ) > $total )
{
$start = ( $total - $max );

// If $start is less then 0, $start = 0
if( $start < 0 )
{
$start = 0;
}

}

$query_fetch = mysql_query($sql . " LIMIT " . $start . ", " . $max) or die (mysql_error());

echo "<table width=\"95&#37;\" border=\"2\" >
<tr>
<th>JOB CODE</th>
<th>JOB SUBJECT</th>
<th>JOB DESCRIPTION</th>
<th>NUMBER OF OPENINGS</th>
<th>POST DATE</th>
<th>LAST DATE</th>
<th>CANDIDATE ID</th>
<th>FIRST NAME</th>
<th>LAST NAME</th>
<th>RESUME</th>
</tr>";

while( $row = mysql_fetch_array( $query_fetch ) )
{

echo "<tr>";
echo "<td>" . $row['jobcode'] . "</td>";
echo "<td>" . $row['subject'] . "</td>";
echo "<td>" . $row['description'] . "</td>";
echo "<td>" . $row['opening'] . "</td>";
echo "<td>" .$row['postdate'] . "</td>";
echo "<td>" . $row['lastdate'] . "</td>";
echo "<td>" .$row['candidate_id'] . "</td>";
echo "<td>" . $row['firstname'] . "</td>";
echo "<td>" . $row['lastname'] . "</td>";
echo("<td>");
echo("<a href='" . $row['resume'] . " ' target = '_blank' >" );
echo("<br/>" . $row['resume'] . "</a>");
echo("</td>");
echo "</tr>";

}

echo "</table>";

echo "<p>" . mkPagination($start, $max, $total, $paginLimit) . "</p>";

}
else
{
echo "<p align=\"center\">NO PROFILES MATCH THE CRITERIA GIVEN.</p>";
}
?>

Tell me if it was as you want it! ;)

Best regards,
mbrodin