Page 1 of 1

Need help with printing out database rows!!

Posted: Tue Oct 20, 2009 2:12 pm
by microsekund
Hi i need some help, i have a script that prints out all usernames and scores from a database, but i want it to just print out 10 rows and not all of them and add a link that lets you see the other 10 rows.
so if i have 30 rows in that database i want it to print out 3 links the first lets you se the first 10 rows then the second lets you see the rows from 10 to 20 and so on, hope you understand what im mean, im not very good at explain things.
whell here is the script i got

Code: Select all

<?php
include("/inc/connect.php");
 
if (mysqli_connect_errno()) {
    die (mysqli_connect_error());
}
echo "<center><table><tr><td class='tdstyle'>Score</td><td class='tdstyle1'> Username </td></tr></table></center>";
$sql = 'SELECT * FROM DATABASE ORDER BY score DESC LIMIT 10';
 
$result = $db->query($sql);
if (!$result) {
    die ('Query failed, query was: '.$sql."<br />\nError message: ".$db->error);
}
if (!$result->num_rows) {
    echo '<p class="info">no one is registred</p>';
} else {
    while ($row = $result->fetch_assoc()) {
    $userID="SELECT * from eatyou_login where id ='.$row[id].'";
    $getscore2=mysql_query($userID) or die("Could not get player");
    $getscore3=mysql_fetch_array($getscore2);
        echo "<center><table><tr><td class='tdstyle'>$getscore3[score]</td><td class='tdstyle1'>$getscore3[username]</td></tr></table></center>";
}
}
?>

Re: Need help with printing out database rows!!

Posted: Tue Oct 20, 2009 2:15 pm
by John Cartwright
There are hundreds of examples of "pagination" here on the boards and google.

Re: Need help with printing out database rows!!

Posted: Tue Oct 20, 2009 2:17 pm
by microsekund
i didnt know what it was called :P but now i know so i can google or something for it thnx.