| | |
PHP MYSQL Paging Problem
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jan 2008
Posts: 16
Reputation:
Solved Threads: 0
Hi, i am having problems displaying the second page of search results. I have applied similar code to a view all logs page which works perfectly but i am having problems making it work with search results. I think it might be a problem with $searchString, not sure???
Please help me!!!
Here is the code --------->
Please help me!!!
Here is the code --------->
PHP Syntax (Toggle Plain Text)
//save keyword from html search form to variable $searchString2 = addslashes($_POST['search2']); if(!empty($searchString2)) { // how many rows to show per page $rowsPerPage = 20; // by default we show first page $pageNum = 1; // if $_GET['page'] defined, use it as page number if(isset($_GET['page'])) { $pageNum = $_GET['page']; } // counting the offset $offset = ($pageNum - 1) * $rowsPerPage; $query = "SELECT * FROM fishinglog WHERE username LIKE '$searchString2' AND private = 'no' ORDER BY date11_date DESC LIMIT $offset, $rowsPerPage "; $result = mysql_query($query); Print "<h3>Search Results for Username: <font color='#76b8f2'>'$searchString2' </font></h3><br />"; Print "<BR>Submit a <a href=newlog.php>Fishing Log</a><BR>"; Print "<BR><a href=viewyourlogs.php>View</a> your Fishing Logs<BR>"; Print "<BR><a href=searchlogs.php>Search</a> members Fishing Logs<BR><BR>"; Print"<hr>"; Print"<table>"; $anymatches01=mysql_num_rows($result); if ($anymatches01 != 0) { Print"<tr><td><font color=#00CCff>Fishing Location</font></td><td><font color=#00CCff>Date</font></td><td><font color=#00CCff>Action</font></td><td><font color=#00CCff>Created by</font></td>"; }else{ Print""; } while ($i = mysql_fetch_array($result)){ print <<<END <tr><td width=200><a href="displaylog.php?fishing_location=$i[fishing_location]&&id=$i[id]">$i[fishing_location]</a></td><td width=100>$i[date11_date] $i[date11_month] $i[date11_year]</td><td width=70>$i[action]</td><td><a href="userinfo.php?user=$i[username]">$i[username]</a></td> END; } Print"</table>"; // how many rows we have in database $query = "SELECT COUNT(*) AS numrows FROM fishinglog WHERE username LIKE '$searchString2' AND private = 'no'"; $result = mysql_query($query) or die('Error, query failed'); $row = mysql_fetch_array($result, MYSQL_ASSOC); $numrows = $row['numrows']; // how many pages we have when using paging? $maxPage = ceil($numrows/$rowsPerPage); // print the link to access each page $self = $_SERVER['PHP_SELF']; $nav = ''; for($page = 1; $page <= $maxPage; $page++) { if ($page == $pageNum) { $nav .= " $page "; // no need to create a link to current page } else { $nav .= " <a href=\"$self?page=$page\">$page</a> "; } } // creating previous and next link // plus the link to go straight to // the first and last page if ($pageNum > 1) { $page = $pageNum - 1; $prev = " <a href=\"$self?page=$page\">[Prev]</a> "; $first = " <a href=\"$self?page=1\">[First Page]</a> "; } else { $prev = ' '; // we're on page one, don't print previous link $first = ' '; // nor the first page link } if ($pageNum < $maxPage) { $page = $pageNum + 1; $next = " <a href=\"$self?page=$page\">[Next]</a> "; $last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> "; } else { $next = ' '; // we're on the last page, don't print next link $last = ' '; // nor the last page link } // print the navigation link echo"<br>"; echo "<center>"; echo $first . $prev . $nav . $next . $last; echo "</center>"; if ($anymatches01 == 0) { echo "Sorry, but your search criteria matched no results<br><br>"; //And we remind them what they searched for echo "<b><a href=searchlogs.php>Search again</a><br><br>"; } }
Last edited by digital-ether; Jan 31st, 2008 at 5:49 pm. Reason: Please highlight your code
•
•
Join Date: Jun 2008
Posts: 1
Reputation:
Solved Threads: 0
hai billy
look into this thread here the same problem you are having is solved.
http://www.webmasterworld.com/forum88/9860.htm
you have to change the start page code?.
if you are not sure use that code given in that site. and change the portion
if(!isset($_GET['start'])) { // This variable is set to zero for the first page
$start = 0;
} else {
$start = $_GET['start'];
}
look into this thread here the same problem you are having is solved.
http://www.webmasterworld.com/forum88/9860.htm
you have to change the start page code?.
if you are not sure use that code given in that site. and change the portion
if(!isset($_GET['start'])) { // This variable is set to zero for the first page
$start = 0;
} else {
$start = $_GET['start'];
}
![]() |
Similar Threads
- I need a great web designer and proffesional PHP Coder ~ 10k project (Web Development Job Offers)
- multiple search terms+fulltext search (MySQL)
- Paging Problem (PHP)
Other Threads in the PHP Forum
- Previous Thread: Good PHP Documents
- Next Thread: How to Put Icon on PHP
| Thread Tools | Search this Thread |
.htaccess ajax apache api archive array autocomplete beginner binary broken cakephp checkbox class cms code cron curl database dataentry date directory display download dynamic echo email emptydisplayvalue error errors execute explodefunction file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla keywords limit link login loop mail menu mlm mod_rewrite multiple mysql oop oracle paypal pdf php problem query radio random recursion recursive regex remote script search server sessions shot sms soap source space sql subscription syntax system table tutorial tutorials update upload url validation validator variable video web xml youtube





