| | |
problem with links in pagination
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Apr 2008
Posts: 35
Reputation:
Solved Threads: 0
hi, i just wrote a program for my website with a search function. everything works fine but i have a problem with the links to the other result pages. this is the code
note: one lines 82, 92 and 100 where i put the links to the other pages, i also tried: href='job_search.php'?keyword.......
the idea is that when one clicks on the links, a new query would be built so the variables required for the query are passed in the link.
ALSO: does anyone know how i can modify this code to show details when a user click on the results
if anybody knows what's wrong, please help me out
thanks
text Syntax (Toggle Plain Text)
<?php $errors = array(); if ($_POST) { $mysql = mysql_connect("localhost", "root", "") or die("couldn't connect to server"); $db = mysql_select_db("jobpage", $mysql) or die("couldn't connect to database"); $keyword = $_REQUEST["keyword"]; $place = $_REQUEST["place"]; $cat_id = $_REQUEST["cat_id"]; $limit = $_REQUEST['limit']; $page = $_REQUEST['page']; //set defaults for $limits, $page if (!($limit) || (is_numeric($limit) == "false") || ($limit < 10) || ($limit > 50)) { $limit = 10; } if (!($page) || (is_numeric($page) == "false") || ($page > $numrows) || ($page <= 0)) { $page = 1; } // set the lower limit where the records would start to display $start_limit = $page * $limit - $limit; //build search query first against only the keyword-- $search_db = "SELECT * FROM jobs WHERE job_desc like \"%$keyword%\""; $search_res = mysql_query($search_db) or die(mysql_error()); $numrows = mysql_num_rows($search_res); if ($numrows == 0) die ("no matches met your criteria"); // set the total number of pages required $total_pages = ceil($numrows/$limit); $search_db = "SELECT * FROM jobs WHERE job_desc like \"%$keyword%\" LIMIT $start_limit, $limit"; $search_res = mysql_query($search_db) or die(mysql_error()); // display what the person searched for $display .=" <p>You searched for: "" . $keyword . ""</p>"; // begin to show results set $b = $start_limit + $limit; $start_limit++; if ($numrows < $limit){ $display .= "<p>Showing results $start_limit to $numrows of $numrows</p>"; } else{ $display .= "<p>Showing results $start_limit to $b of $numrows</p>"; } //first build the top part of the table $display .= "<TABLE BORDER = '1'>"; $display .= "<TR>"; $display .= "<TH>Job Title</TH><TH>Company</TH><TH>Description</TH><TH>Pay</TH><TH>Location</TH><TH>Date</TH>"; $display .= "</TR>"; // now you can display the results returned while ($row = mysql_fetch_array($search_res)) { $title = $row["job_title"]; $desc = $row["job_desc"]; $qua = $row["job_qua"]; $pay = $row["job_pay"]; $req = $row["job_req"]; $date = $row["post_date"]; $comp = $row["comp_name"]; $loc = $row["job_loc"]; $display .= "<TR>"; $display .= "<TD> $title</TD><TD> $comp </TD><TD> $desc </TD><TD> $pay </TD><TD> $loc </TD><TD> $date </TD>"; $display .= "</TR>"; //$count++;// total number of records shown which will be the set_limit, starting point of our limit clause } $display .= "</TABLE>"; $previous_page = $page -1; if ($previous_page >=1){ $display .= "<b><<</b> <a href=".$_SERVER["PHP_SELF"]."?keyword=$keyword&limit=$limit&page=$prev_page><b>Prev.</b></a>"; } //loop through other pages for ($a = 1; $a <= $total_pages; $a++){ if ($a == $page){ $display .= "<b>$a | </b>"; } else { $display .= "<a href='".$_SERVER["PHP_SELF"]."?keyword=$keyword&limit=$limit&page=$a'> $a </a> |"; } } $next_page = $page +1; if ($next_page <=$total_pages){ $display .= "<a href=".$_SERVER["PHP_SELF"]."?keyword=$keyword&limit=$limit&page=$next_page><b>Next</b></a> > >"; } } else { header("location: sbd.html"); } ?>
note: one lines 82, 92 and 100 where i put the links to the other pages, i also tried: href='job_search.php'?keyword.......
the idea is that when one clicks on the links, a new query would be built so the variables required for the query are passed in the link.
ALSO: does anyone know how i can modify this code to show details when a user click on the results
if anybody knows what's wrong, please help me out
thanks
Last edited by cali_dotcom; Oct 9th, 2008 at 12:18 am.
•
•
Join Date: Apr 2008
Posts: 35
Reputation:
Solved Threads: 0
the problem is with the links on lines 82, 92 and 100.
the links do appear but when they are clicked on, the variables are not passed on to the script, hence i get a "page not found" page instead of a new query to be built and the script be run again.
i really dont know what's wrong, i'm losing my mind on this.
the links do appear but when they are clicked on, the variables are not passed on to the script, hence i get a "page not found" page instead of a new query to be built and the script be run again.
i really dont know what's wrong, i'm losing my mind on this.
•
•
•
•
the problem is with the links on lines 82, 92 and 100.
the links do appear but when they are clicked on, the variables are not passed on to the script, hence i get a "page not found" page instead of a new query to be built and the script be run again.
i really dont know what's wrong, i'm losing my mind on this.
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss
-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
•
•
Join Date: Apr 2008
Posts: 35
Reputation:
Solved Threads: 0
•
•
•
•
I'm pretty sure you need to replace "&" with "&" in the links
here is the new code:
PHP Syntax (Toggle Plain Text)
<?php $mysql = mysql_connect("localhost", "root", "") or die("couldn't connect to server"); $db = mysql_select_db("jobpage", $mysql) or die("couldn't connect to database"); $keyword = $_GET["keyword"]; $place = $_REQUEST["place"]; $cat_id = $_REQUEST["cat_id"]; $limit = $_GET["limit"]; $page = $_GET["page"]; //set defaults for $limits, $page if (!($limit) || (is_numeric($limit) == "false") || ($limit < 10) || ($limit > 50)) { $limit = 10; } if (!($page) || (is_numeric($page) == "false") || ($page > $numrows) || ($page <= 0)) { $page = 1; } // set the lower limit where the records would start to display $start_limit = ($page * $limit) - $limit; //build search query first against only the keyword-- $search_db = "SELECT * FROM jobs WHERE job_desc like \"%$keyword%\""; $search_res = mysql_query($search_db) or die(mysql_error()); //get all columns $numrows = mysql_num_rows($search_res); if ($numrows == 0) die ("no matches met your criteria"); // set the total number of pages required $total_pages = ceil($numrows/$limit); $db = "SELECT * FROM jobs WHERE job_desc like \"%$keyword%\" LIMIT $start_limit, $limit"; $res = mysql_query($db) or die(mysql_error()); //get the number of rows to be displayed $numrows1 = mysql_num_rows($res); // display what the person searched for $display .=" <p>You searched for: "" . $keyword . ""</p>"; // begin to show results set $b = $start_limit + $limit; $start_limit= $start_limit + 1; if ($numrows1 < $limit){ $display .= "<p>Showing results $start_limit to $numrows1 of $numrows</p>"; } else{ $display .= "<p>Showing results $start_limit to $b of $numrows</p>"; } //first build the top part of the table $display .= "<TABLE BORDER = '1'>"; $display .= "<TR>"; $display .= "<TH>Job Title</TH><TH>Company</TH><TH>Description</TH><TH>Pay</TH><TH>Location</TH><TH>Date</TH>"; $display .= "</TR>"; // now you can display the results returned while ($row = mysql_fetch_array($res)) { $title = $row["job_title"]; $desc = $row["job_desc"]; $qua = $row["job_qua"]; $pay = $row["job_pay"]; $req = $row["job_req"]; $date = $row["post_date"]; $comp = $row["comp_name"]; $loc = $row["job_loc"]; $display .= "<TR>"; $display .= "<TD> $title</TD><TD> $comp </TD><TD> $desc </TD><TD> $pay </TD><TD> $loc </TD><TD> $date </TD>"; $display .= "</TR>"; //$count++;// total number of records shown which will be the set_limit, starting point of our limit clause } $display .= "</TABLE>"; $prev_page = $page -1; if ($prev_page >=1){ $display .= '<b>«</b> <a href="'.$_SERVER["PHP_SELF"].'?keyword='.$keyword.'&limit='.$limit.'&page='.$prev_page.'"><b>Prev.</b></a>'; } //loop through other pages for ($a = 1; $a <= $total_pages; $a++){ if ($a == $page){ $display .= "<b>$a | </b>"; } else { $display .= '<a href="'.$_SERVER["PHP_SELF"].'?keyword='.$keyword.'&limit='.$limit.'&page='.$a.'"><b>'.$a.'</b></a> |'; } } $next_page = $page +1; if ($next_page <=$total_pages){ $display .= '<a href="'.$_SERVER["PHP_SELF"].'?keyword='.$keyword.'&limit='.$limit.'&page='.$next_page.'"><b>Next</b></a>> >'; } ?>
I think $numrows around line 22 when you are checking the value of $page is not defined so the value of $page will always be 1.
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss
-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
•
•
Join Date: Apr 2008
Posts: 35
Reputation:
Solved Threads: 0
•
•
•
•
I think $numrows around line 22 when you are checking the value of $page is not defined so the value of $page will always be 1.
thanks rob,
the problem was $page and $limit were always set to the default of 1 an 10 respectively because the conditions is_numeric($page) and is_numeric($limit) was always returning false. i put this condition in just incase someone typed in the values in the url as security measure. as soon as i took them out all was fine. do you know any way i could block values that have been type directly into the url.
thanks..
![]() |
Similar Threads
- how to view image in Msql (PHP)
- Pagination Help (PHP)
- replace address - how to? (PHP)
- Pagination - not displaying results properly, please help! (PHP)
- PHP Search pagination problem (PHP)
Other Threads in the PHP Forum
- Previous Thread: Text only Browse button
- Next Thread: IE is reversing the menu order
| Thread Tools | Search this Thread |
301 apache api array autosuggest beginner binary broken cakephp checkbox class cms code compression cron curl data database date display dropdownlist dynamic echo email eregi error execution file files folder form forms function functions google href htaccess html httppost if...loop image include insert ip javascript joomla jquery key library limit link links login mail md5 menu mlm multiple mysql mysql_real_escape_string oop paypal pdf pdfdownload php phpvotingscript problem query radio random recursion remote screen script search searchbox server session sessions sms sorting source space sql syntax system table tutorial update upload url validator variable video volume votedown web website youtube zend





