[thelist] Help me please
amar lastname
amarafzal at yahoo.com
Thu Mar 27 08:30:16 CST 2003
Im tryed to use the code that displays the next page
etc. I can get most of the code to work, the problem
is when the user clicks on next, it comes out blank.
The select statement has a $query variable in select
statement:
$results = mysql_query("SELECT * FROM your_table WHERE
name LIKE '%". $query ."%' ORDER BY name ASC LIMIT
$page, $limit");
my query is as follows:
$numresults = mysql_query("select * from $table_name
where job_sector = '$_POST[job_sector]' AND region =
'$_POST[region]'"); // the query.
how do i get the query varibale to work in my query?
that variable is in the next link. IM desperate for
some help.
My full code is:
if (!($limit)){
$limit = 1;} // Default results per-page.
if (!($page)){
$page = 0;} // Default page value.
$numresults = mysql_query("select * from $table_name
where job_sector = '$_POST[job_sector]' AND region =
'$_POST[region]'"); // the query.
$numrows = mysql_num_rows($numresults); // Number of
rows returned from above query.
$pages = intval($numrows/$limit); // Number of results
pages.
// $pages now contains int of pages, unless there is a
remainder from division.
if ($numrows % $limit) {
$pages++;} // has remainder so add one page
$current = ($page/$limit) + 1; // Current page number.
if (($pages < 1) || ($pages == 0)) {
$total = 1;} // If $pages is less than one or equal to
0, total pages is 1.
else {
$total = $pages;} // Else total pages is $pages value.
$first = $page + 1; // The first result.
if (!((($page + $limit) / $limit) >= $pages) && $pages
!= 1) {
$last = $page + $limit;} //If not last results page,
last result equals $page plus $limit.
else{
$last = $numrows;} // If last results page, last
result equals total number of results.
?>
<?
// Now we can display results.
$results = mysql_query("select * from $table_name
where job_sector = '$_POST[job_sector]' AND region =
'$_POST[region]' ORDER BY date_posted ASC LIMIT $page,
$limit"); // the query.
while ($row = mysql_fetch_array($results))
{
$candidate_id = $row['candidate_id'];
$what_they_do = stripslashes($row['what_they_do']);
$contact_phone = $row['contact_phone'];
$contact_name = $row['contact_name'];
$contact_email = $row['contact_email'];
$date_posted = $row['date_posted'];
$job_title = stripslashes($row['job_title']);
$candidate_description =
stripslashes($row['cand_description']);
$short_summary = substr($candidate_description,0,150);
$location = stripslashes($row['location']);
$salary = $row['salary'];
$display_block .= "
<table width=80% border=0 cellspacing=1 cellpadding=0>
<tr bgcolor=#FFEBD7>
<td><a
href=candidate_detail.php?candidate_id=$candidate_id>$what_they_do</a><br>$short_summary....<a
href=candidate_detail.php?candidate_id=$candidate_id>[More]</a><br><strong>Anticipated
Salary:</strong> $salary
</td>
<td width=26% valign=top>$location</td>
</tr>
</table>";
}
?>
<?
if ($page != 0) { // Don't show back link if current
page is first page.
$back_page = $page - $limit;
echo("<a
href=\"$PHP_SELF?query=$query&page=$back_page&limit=$limit\">[<
Back]</a>\n");}
for ($i=1; $i <= $pages; $i++) // loop through each
page and give link to it.
{
$ppage = $limit*($i - 1);
if ($ppage == $page){
echo("<b>$i</b>\n");} // If current page don't give
link, just text.
else{
echo("<a
href=\"$PHP_SELF?query=$query&page=$ppage&limit=$limit\">$i</a>
\n");}
}
if (!((($page+$limit) / $limit) >= $pages) && $pages
!= 1) { // If last page don't give next link.
$next_page = $page + $limit;
echo("<a
href=\"$PHP_SELF?query=$query&page=$next_page&limit=$limit\">[Next
>]</a>");}
?>
__________________________________________________
Do you Yahoo!?
Yahoo! Platinum - Watch CBS' NCAA March Madness, live on your desktop!
http://platinum.yahoo.com
More information about the thelist
mailing list