joecooper Posted August 28, 2008 Share Posted August 28, 2008 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++; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/121762-problem-with-query-loop/ Share on other sites More sharing options...
BlueSkyIS Posted August 28, 2008 Share Posted August 28, 2008 could you re-phrase your post in the form of a question? kthxbai Quote Link to comment https://forums.phpfreaks.com/topic/121762-problem-with-query-loop/#findComment-628168 Share on other sites More sharing options...
wildteen88 Posted August 28, 2008 Share Posted August 28, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/121762-problem-with-query-loop/#findComment-628170 Share on other sites More sharing options...
joecooper Posted August 28, 2008 Author Share Posted August 28, 2008 sorry about that. the code doesnt return anything. the first 2 are the latest ones and go at the top of the page together, the rest should go in a table at the bottom. www.joeyjoe.co.uk/oag/index.php <-- see? Quote Link to comment https://forums.phpfreaks.com/topic/121762-problem-with-query-loop/#findComment-628175 Share on other sites More sharing options...
kratsg Posted August 28, 2008 Share Posted August 28, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/121762-problem-with-query-loop/#findComment-628179 Share on other sites More sharing options...
joecooper Posted August 28, 2008 Author Share Posted August 28, 2008 i have no idea how to use them. ignore the idea of skipping the first 2 for now. i need to have a loop that every entery will create a new line on a table. Quote Link to comment https://forums.phpfreaks.com/topic/121762-problem-with-query-loop/#findComment-628186 Share on other sites More sharing options...
kratsg Posted August 28, 2008 Share Posted August 28, 2008 <?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]. Quote Link to comment https://forums.phpfreaks.com/topic/121762-problem-with-query-loop/#findComment-628192 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.