Jump to content

Recommended Posts

I was the code to skip the first 2 entrys returned, and then loop though the other entrys in the table and display the html code (unfinished)

 

<?php

include("db.php");
$query = mysql_query("SELECT * FROM games ORDER BY id DESC");

$i = 1;
while ($row = mysql_fetch_assoc($query)){
   if ($i == 1 || $i == 2){
   }else{
   echo "test";
?>


  <tr>
    <td width="50" height="100" bgcolor="#666666"> </td>
    <td width="102" height="100" bgcolor="#999999"style="border-bottom:1px solid #FFFFFF; border-left:1px solid #FFFFFF; border-right:1px solid #FFFFFF;> </td>
    <td bgcolor="#666666"> </td>
    <td width="10" bgcolor="#666666"> </td>
    <td width="638" bgcolor="#666666"><span class="style3">This is the game description. This will give all the interesting info about the game and why the user should play it </span></td>
  </tr>
  
<?php    
   }

$i++;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/121762-problem-with-query-loop/
Share on other sites

I was the code to skip the first 2 entrys returned, and then loop though the other entrys in the table and display the html code (unfinished)

Why do you want to skip the first two entries from the result set? Do you not want the query the return the first two rows from the games table?

 

However your code as it is not recommended, but it should work.

Try doing something along these lines:

 

<?php

$num_rows = mysql_num_rows($query) - 2;//return the number of results excluding the first two

$query123 = mysql_query($query. "LIMIT 2,".$num_rows);//return all rows from the third result on

?>

 

This logic works in the following sense:

 

If you have 10 results, ordered from 0,1,2,3,4,5,6,7,8,9 [for instance].

 

$num_rows = 10 - 2 = 8.

 

The query will then fetch 8 rows starting from record #2: 2,3,4,5,6,7,8,9.

<?php

include("db.php");
$query = mysql_query("SELECT * FROM games ORDER BY id DESC");

echo "<table>";//start the table tag

while ($row = mysql_fetch_assoc($query)){
?>


  <tr>
    <td width="50" height="100" bgcolor="#666666"> </td>
    <td width="102" height="100" bgcolor="#999999"style="border-bottom:1px solid #FFFFFF; border-left:1px solid #FFFFFF; border-right:1px solid #FFFFFF;> </td>
    <td bgcolor="#666666"> </td>
    <td width="10" bgcolor="#666666"> </td>
    <td width="638" bgcolor="#666666"><span class="style3">This is the game description. This will give all the interesting info about the game and why the user should play it </span></td>
  </tr>
  
<?php    
}
echo "</table>";//end the table tag
?>

 

I modified the above code provided just for your simple request of having it create a new row for each entry. Please note that your html has errors in it (missing quotations, incorrect CSS, etc..) and needs to be fixed before you attempt to echo it out with PHP [the above will echo out the html just fine, but it's not the best way to echo it out if you want to include information from the database].

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.