I must begin by apologizing for the lengthiness of this posting but I really couldn’t edit it to be any shorter. Hopefully one of you reading this is quite familiar with both PHP pagination, and displaying search results in rows. Well here’s what I’m trying to do. I created a page that displays results from a simple search query. the results displayed are the pictures of a users of a website, alongside their usernames. I’m trying to display the results in rows of 4, as dictated by the $items variable on line 27 of the script i will post below in a minute. Well, the script works just fine as intended. Then when I add the blocks of code that should paginate the results (the pagination blocks of code are indented to the left of the script), I run into a bunch of problems. First of all, oddly enough, when I set the number of rows to be displayed per page to any number order than 4, the page never completes the loading process and the pagination links are not displayed. The page only loads fully and displays the pagination links when $numrows is set to 4 and even then, when I click on the link to take me to the next page, no results get displayed. Instead I get the "No results match this search query’ message which is displayed when the query returns no results. It seems to me like there are problems with the pagination code, I’m not quite sure. I have tried about 3 different pagination codes which I found from online tutorials and they all present the same problems. Any help? Here is my page.
PS One more problem, when I set the $limit variable(which sets the number of results displayed per row) to 4, the data to be displayed(pictures) get extra padding between them, pushing the last one out of the page. Ironically as explained above, this is the only case where the page loads completely and the pagination links get displayed. To make you picture this easier, I have removed the authentication restrcition off this page and I’ll provide the link for you to see what I’m talking about http://mygeneric.info/search_results.php?ethnicity=white [php]
<?php //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); //authenticate user require('auth.php'); //Set session timeout require('inactive.php'); //Set the page title before the header file $title = 'Search Results'; //Get variables from previous page, profile_searh.php $ethnicity = $_GET['ethnicity']; //Items to display per row. $items = 4; require ('header.php'); //need the header echo'Could not retrieve the data because: ' . mysql_error(). '
'); // Handle as desired }else{ //If query is valid. if(mysql_num_rows($result) > 0){ //Start a table to contain the results. echo '
";
//Define variables to be passed via url.
$friend= $row['member_id'];
//Make sure an uploaded photo is present. if ($row['image'] !== NULL) {
echo"";
// Note that we are building our src string using the filename from the database.
echo "
" .$row['username']. "//End of if there is an uploaded pic.} | \n";
//Icrement the counter.
$i++;
//Do we need to end the row?
if ($i == $items) {echo "\n"; } //Complete the row. echo ''; }//End of if $i is greater than 0 //Close the table. echo ' |
[/php]