How to display query result that is not yet displayed??

hello guys, i am a student studying php and sql. I have 20 persons in my database, I already have a query that will display 10 persons order by average in descending, and i want to display the next 10 persons that are not included on the first result.

hope you guys can help me…

here is the code:
[php]<?php
$host = “localhost”;
$user = “root”;
$pass = “”;
$db = “enrolledgrade7”;

mysql_connect($host, $user, $pass);
mysql_select_db($db);

$query = “SELECT * FROM student ORDER BY average DESC”;
$result = mysql_query($query);
$num = mysql_numrows($result);

echo “Section1”;
echo “

”;
$i=0;
while ($i < 10) {
 $studentID = mysql_result($result, $i, "studentID");
 $firstname = mysql_result($result, $i, "firstname");
 $lastname = mysql_result($result, $i, "lastname");
 $average = mysql_result($result, $i, "average");

 echo "<tr><td>$studentID</td><td>$lastname, $firstname</td><td>$average</td></tr>";

$i++;
}

echo “

StudentID Name average
”;

?>[/php]

I’m not really sure what you are trying to do. Do you want to have a new table for every 10 people?

Yes, I want to have a new table for every 10 people. thanks for the reply.

You could do something like this

[php]
while ($i < 10) {
$studentID = mysql_result($result, $i, “studentID”);
$firstname = mysql_result($result, $i, “firstname”);
$lastname = mysql_result($result, $i, “lastname”);
$average = mysql_result($result, $i, “average”);

echo "<tr><td>$studentID</td><td>$lastname, $firstname</td><td>$average</td></tr>";

// end and create a new table every 10 rows
if (($i + 1) % 10 === 0) {
	echo "</table>";
	echo "<table cellpadding=2 border=1><tr><td>StudentID</td><td>Name</td><td>average</td></tr>";
}
$i++;

}
[/php]

i can already create a new table but how can i display data that is not yet displayed at the first table? thanks for the reply

If you change how the loop is done you can loop all rows

For example

[php]
echo “Section1”;
echo “

”;

$i = 1;
while($row = mysql_fetch_assoc($result)) {
echo “

”;
// end and create a new table every 10 rows
if ($i % 10 === 0) {
	echo "</table>";
	echo "<table cellpadding=2 border=1><tr><td>StudentID</td><td>Name</td><td>average</td></tr>";
}
$i++;

}

echo “

StudentID Name average
” . $row[‘studentID’] . “ ” . $row[‘lastname’] . ", " . $row[‘firstname’] . “ ” . $row[‘average’] . “
”;
[/php]

it works, hope this post can help others too. Thanks for the help m@tt and thank you www.phphelp.com

Sponsor our Newsletter | Privacy Policy | Terms of Service