Need help with printing out database rows!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
microsekund
Forum Newbie
Posts: 2
Joined: Tue Oct 20, 2009 2:03 pm

Need help with printing out database rows!!

Post 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>";
}
}
?>
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Need help with printing out database rows!!

Post by John Cartwright »

There are hundreds of examples of "pagination" here on the boards and google.
microsekund
Forum Newbie
Posts: 2
Joined: Tue Oct 20, 2009 2:03 pm

Re: Need help with printing out database rows!!

Post by microsekund »

i didnt know what it was called :P but now i know so i can google or something for it thnx.
Post Reply