Jump to content

A little porblem in my query.


cyrixware

Recommended Posts

i have a problem on the query... i want every pages (using pagination) display each rank. well, on the current page let say if i have 40 ID's stored in the database. i want to limit to = 20 ID's per page (using pagination) the rank is ok. but when i click "next/>>" to the next page the rank generated a new top's on the current page.

 

EX: Page 1

 

==== ID ==== RANK

==== 01 ==== 1

==== 02 ==== 1

==== 06 ==== 2

==== 10 ==== 3

==== 12 ==== 3

 

Problem? Supposed to be the rank will increase just like rank 4,5,6 or up....

EX: Page 2

 

==== ID ==== RANK

==== 13 ==== 1

==== 22 ==== 2

==== 26 ==== 2

==== 30 ==== 3

==== 32 ==== 3

 

heres the code:

 

<?php

include("../connDB.php");

$Limit = 50; //Number of results per page
$SearchString=$_POST["row_id"]; // Get the search tearm

$page=$_GET["page"]; //Get the page number to show
If($page == "") $page=1; //If no page number is set, the default page is 1

//Get the number of results
$SearchResult = mysql_query("SELECT studentgrade.SuGrade, studentgrade.SuID, student.SuID, student.SuFirstname, student.SuMiddlename, student.SuLastname FROM 
	                     studentgrade, student WHERE studentgrade.SuID = student.SuID ORDER BY SuGrade DESC") or die(mysql_error());
$NumberOfResults = mysql_num_rows($SearchResult);

//Get the number of pages
$NumberOfPages = ceil($NumberOfResults/$Limit);
$SearchResult = mysql_query("SELECT studentgrade.SuGrade, studentgrade.SuID, student.SuID, student.SuFirstname, student.SuMiddlename, student.SuLastname FROM 
	                     studentgrade, student WHERE studentgrade.SuID = student.SuID ORDER BY SuGrade LIMIT " . ($page-1)*$Limit . ",$Limit") or die(mysql_error());
if(mysql_num_rows($SearchResult) > 0)
{
	$i = 0;
-------------------
?>

 

<?php
	while($row = mysql_fetch_assoc($SearchResult))
        {
			if($row['SuGrade'] != $score)
			{
				$i++;
			}
?>
----------------

<?php $id = $row['SuID']; echo"$id";?>
<?php $grade = $row['SuGrade']; echo"$grade";?>
    }
}

<?php
$Nav="";
If($page > 1) {
$Nav .= "<A HREF=\"averageRank.php?page=" . ($page-1) . "\"><<</A>";
}else{
$Nav .= " << ";
}
For($i = 1 ; $i <= $NumberOfPages ; $i++) {
If($i == $page) {
	$Nav .= "<font color=#FF0000 size=2 face=Verdana, Arial, Helvetica, sans-serif><B>$i</B></font>";
}Else{
	$Nav .= "<A HREF=\"averageRank.php?page=" . $i ."\"> $i </A>";
}
}
If($page < $NumberOfPages) {
$Nav .= "<A HREF=\"averageRank.php?page=" . ($page+1) .  "\">>></A>";
}else{
$Nav .= " >> ";
}
Echo "" . $Nav;
$sql_count = "SELECT COUNT(*) FROM student";
$q_count = mysql_query($sql_count);
?>

 

pls help em..

Link to comment
https://forums.phpfreaks.com/topic/94437-a-little-porblem-in-my-query/
Share on other sites

I think the problem is in this part:

 

<?php
	while($row = mysql_fetch_assoc($SearchResult))
        {
			if($row['SuGrade'] != $score)
			{
				$i++;
			}
                 $id = $row['SuID']; echo"$id";
                 $grade = $row['SuGrade']; echo"$grade";
                 }
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.