Paginatating PHP
| From: | Chris Carter | Date: | Wed, 20 Dec 2006 17:24:41 +0000 |
| Subject: | Paginatating PHP | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-42829@lists.php.net to get a copy of this message | ||
Why is this code that I have written to paginate the result from database
jumping to else condition where the NEXT or PREVIOUS is not hyperlinked as
in the if condition. There is enough data to display this result and to
paginate but its simply showing the else condition which does not have NEXT
or PREVIOUS hyperlinked.
--------------------- CODE -------------------------
$host = 'xxx';
$user = 'xxx';
$password = 'xxx';
$database = 'xxx';
@mysql_connect($host, $user, $password) or die("ERROR--CAN'T CONNECT TO
SERVER");
@mysql_select_db($database) or die("ERROR--CAN'T CONNECT TO DB");
$limit = 15;
$query_count = "SELECT count(*) FROM students";
$result_count = mysql_query($query_count);
$totalrows = mysql_num_rows($result_count);
if(empty($page)){
$page = 1;
}
$limitvalue = $page * $limit - ($limit);
$query = "SELECT * FROM students LIMIT $limitvalue, $limit";
$result = mysql_query($query) or die("Error: " . mysql_error());
if(mysql_num_rows($result) == 0){
echo("Nothing to Display!");
}
$bgcolor = "#E0E0E0"; // light gray
echo("<table>");
while($row = mysql_fetch_array($result)){
if ($bgcolor == "#E0E0E0"){
$bgcolor = "#FFFFFF";
}else{
$bgcolor = "#E0E0E0";
}
echo("<tr bgcolor=".$bgcolor."> <td>");
echo($row["name"]);
echo("</td>n<td>");
echo($row["major"]);
echo("</td>n</tr>");
}
echo("</table>");
if($page != 1){
$pageprev = $page--;
echo(" \"$PHP_SELF&page=$pageprev\" PREV".$limit." ");
}else{
echo("PREV".$limit." ");
}
$numofpages = $totalrows / $limit;
for($i = 1; $i <= $numofpages; $i++){
if($i == $page){
echo($i." ");
}else{
echo(" \"$PHP_SELF?page=$i\" $i ");
}
}
if(($totalrows % $limit) != 0){
if($i == $page){
echo($i." ");
}else{
echo(" \"$PHP_SELF?page=$i\" $i ");
}
--
View this message in context: http://www.nabble.com/Paginatating-PHP-tf2861083.html#a7994164
Sent from the Php - Database mailing list archive at Nabble.com.