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.ph ... city=white
Code: Select all
<?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' <div id="content" class="">
<div id="left_content" class="">
</div> <!--closes left content-->
<div id="right_content" class="">
<div id= "right_content_inner_border"> ';
//Obtain the required page number from the $_GET array. Note that if it is not present it will default to 1.
if (isset($_GET['pageno'])) {
$pageno = $_GET['pageno'];
} else {
$pageno = 1;
} // if
// Connect to the database.
require_once ('config.php');
//Count how many rows will satisfy the current query..
$query = "SELECT* FROM members INNER JOIN images ON members.member_id = images.member_id WHERE members.ethnicity = '$ethnicity' AND images.image_cartegory = 'main' ";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
//Use the values in $rows_per_page and $numrows in order to identify the number of the last page.
$rows_per_page = 4;
$lastpage = ceil($numrows/$rows_per_page);
//Check that the value of $pageno is an integer between 1 and $lastpage.
$pageno = (int)$pageno;
if ($pageno > $lastpage) {
$pageno = $lastpage;
} // if
if ($pageno < 1) {
$pageno = 1;
} // if
//Construct the LIMIT clause for the sql SELECT statement.
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
//Now we can issue the database qery and process the result.
$query = "SELECT* FROM members INNER JOIN images ON members.member_id = images.member_id WHERE members.ethnicity = '$ethnicity' AND images.image_cartegory = 'main' $limit ";
$result = mysql_query($query) or die(mysql_error());
//Check for success here.
if(!$result)
{
die('<p>Could not retrieve the data because: <b>' . mysql_error(). '</p>');
// Handle as desired
}else{ //If query is valid.
if(mysql_num_rows($result) > 0){
//Start a table to contain the results.
echo '<table border= "0" width="100%" cellspacing= "1" cellpadding ="1" align ="center"> ';
//Need a counter.
$i = 0;
//Retrieve each record.
while ($row = mysql_fetch_assoc($result)){
//Do we need to start a new row?
if($i == 0) {echo "<tr>\n";}
//Print the record
echo"\t<td align=\"center\">
<div id='search_pic_wrap'>
<div id='no_photo'>";
//Define variables to be passed via url.
$friend= $row['member_id'];
//Make sure an uploaded photo is present. if ($row['image'] !== NULL) {
echo"<a href='friend.php?friend=$friend' >";
// Note that we are building our src string using the filename from the database.
echo "<img src=\"images/" . $row['image'] . "\" width=\"140\" maxheight=\"154\" />";
echo "</a>";
echo"<h2 style= 'position:relative;bottom:25px;'>" .$row['username']. "</h2>
//End of if there is an uploaded pic.}
</div> <!--closes no photo-->
</div> <!--closes search pic wrap-->
</td>\n";
//Icrement the counter.
$i++;
//Do we need to end the row?
if ($i == $items) {echo "</tr>\n";
$i = 0; //Reset counter.
}
}//End of while loop.
if ($i > 0) {//Last row was incomplete.
//Print the necessary number of cells.
for ($i < $items; $i++;) { echo "<td> </td>\n";
}
//Complete the row.
echo '</tr>';
}//End of if $i is greater than 0
//Close the table.
echo '</table>';
echo '<div style= " position:absolute;top:1050px;left:600px;">';
//Construct the hyperlinks which will allow the user to select other pages. We will start with the links for any previous pages.
if ($pageno == 1) {
echo " FIRST PREV ";
} else {
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a> ";
$prevpage = $pageno-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a> ";
} // if
//Inform the user of his current position in the sequence of available pages.
echo " ( Page $pageno of $lastpage ) ";
//Provide the links for any following pages.
if ($pageno == $lastpage) {
echo " NEXT LAST ";
} else {
$nextpage = $pageno+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT</a> ";
echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>LAST</a> ";
} // if
echo'</div>';
}else {//No rows returned. End of if number of rows is greater than 0 loop.
echo 'No results match this search query.' ;
}
}//End of else if query is valid.
echo'
</div> <!--closes right content inner border-->
</div> <!--closes right content-->
</div> <!--closes content--> ';
require ('footer.php'); //need the footer
?>