...

View Full Version : pagination problem



mhunt
01-05-2007, 05:26 PM
Hi can anyone take a look at my code and tell me why the while() loop isn't working?


<?php
session_start();
//check to make sure the session variable is registered//the session variable isn't registered, send them back to the login page
if(!session_is_registered('username')){ header("Location:login.php");}
require_once('Connections/tst.php');

// Sets how many results shown per page
$limit = 25;
// Sets what we want to pull from the database
// count(*) is better for large databases
$query_count = "SELECT count(*) FROM students";
// Pulls what we want from the database
$result_count = mysql_query($query_count);
// This counts the number of users
$totalrows = mysql_num_rows($result_count);
if(empty($page)){ // Checks if the $page variable is empty
$page = 1; // If it is empty, we're on page 1
}
$limitvalue = $page * $limit - ($limit);
//Query to pull info for the students and the organization name
$query = "SELECT students.fname, students.lname, students.email, students.phone1, organization.name AS company FROM students LEFT JOIN organization ON students.organization_id = organization.organization_id LIMIT {$limit}";
$result = mysql_query($query);
if(!$result) {
echo "Problem loading students from the database.".mysql_error();
exit();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="imagetoolbar" content="no">
<title>Technical Support Training</title>
<script type="text/javascript" src="scripts/common.js"></script>
<link href="css/tst.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php
require_once("includes/header.php");
require_once("includes/horz.php");
require_once("includes/nav.php");
?>
<div id="main">
<div id="mainHeader">
<h1>Student Administration </h1>
</div>
<?
if(mysql_num_rows($result) == 0){
echo("Nothing to Display.");
}
$bgcolor = "#E0E0E0";
?>
<table>
<th>First Name</th><th>Last Name</th><th>Phone Number</th><th>Email Address</th><th>Company</th>
<?
echo "outside of the while loop";

while($row == mysql_fetch_array($result)) {
echo "inside the while loop";
if($bgcolor == "#E0E0E0"){
$bgcolor = "#FFFFFF";
}else{
$bgcolor = "#E0E0E0";
}
echo("<tr bgcolor=\".$bgcolor.\">");
?>
<td><? echo($row['fname']); ?></td>
<td><? echo($row['lname']); ?></td>
<td><? echo($row['phone1']); ?></td>
<td><? echo($row['email']); ?></td>
<td><? echo($row['company']); ?></td>
</tr>
<?
}
echo("</table>");

if($page != 1){
$pageprev = $page--;
echo("<a href=\"adminStudents.php&page=$pageprev\">PREV</a> ");
} else {
echo("PREV");
}
$numofpages = $totalrows / $limit;
for($i = 1; $i <= $numofpages; $i++){
if($i == $page){
echo($i." ");
}else{
echo("<a href=\"adminStudents.php&page=$i\">$i</a> ");
}
}
if(($totalrows % $limit) != 0){
if($i == $page){
echo($i." ");
}else{
echo("<a href=\"adminStudents.php&page=$i\">$i</a> ");
}
}
if(($totalrows - ($limit * $page)) > 0){
$pagenext = $page++;
echo("<a href=\"adminStudents.php?page=$pagenext\">NEXT</a>");
}else{
echo("NEXT");
}
mysql_free_result($result);

?>
</div>
</body>
</html>

wordnerd
01-05-2007, 05:47 PM
Sure. Take out the '==' and use a single equals sign.

the '==' is used for comparisons, not for declarations; in this case, you're declaring that $row is the fetched array of the query. You're not comparing anything.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum