Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-05-2007, 05:26 PM   PM User | #1
mhunt
Regular Coder

 
Join Date: Mar 2005
Posts: 111
Thanks: 0
Thanked 0 Times in 0 Posts
mhunt is an unknown quantity at this point
pagination problem

Hi can anyone take a look at my code and tell me why the while() loop isn't working?
PHP Code:
<?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>
mhunt is offline   Reply With Quote
Old 01-05-2007, 05:47 PM   PM User | #2
wordnerd
New Coder

 
Join Date: Dec 2006
Location: Denver, Colorado
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
wordnerd is an unknown quantity at this point
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.
wordnerd is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:39 AM.


Advertisement
Log in to turn off these ads.