Jump to content

list all in DB, apart from first 2


joecooper

Recommended Posts

Hi, this is the code i am using to loop though the database and display all the entrys apart from the first 2 returned:

 

$query = mysql_query("SELECT * FROM games ORDER BY id DESC");
$i = 1;
while ($row = mysql_fetch_assoc($query)){
     if ($i == 1 || $i == 2){
           //do nothing as these are the 2 featured ones and dont need to be displayed here
     }else{
           //code for the table to display data etc...
     }
}

 

but it never returns anything. if i remove the if statement, it works but displays the first 2 that i dont want to include.

Link to comment
https://forums.phpfreaks.com/topic/123234-list-all-in-db-apart-from-first-2/
Share on other sites

increment the "i" value

 

$query = mysql_query("SELECT * FROM games ORDER BY id DESC");
$i = 1;
while ($row = mysql_fetch_assoc($query)){
     if ($i == 1 || $i == 2){
           //do nothing as these are the 2 featured ones and dont need to be displayed here
     }else{
           //code for the table to display data etc...
     }
$i++;
}

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.