Complex While Loop
Posted: Mon Jan 19, 2009 9:03 am
So i have a games website in the making, its getting there... now i want a page that displays 'Full Games List' basically of all the games in my database, now the only way is a while loop, and i tried to first of all use a table - but i wanted it in alphabetical order and i couldnt work out how to go down the columns alphabetically.
So i went for 4 DIVs using a UL. Here is my code, i had to use task manager to close IE as it was stuck in a loop XD
It's quite 'ugly' imo but i had no idea of how else to do it, and i have a feeling that it will just echo the first game in my DB over and over... Any solutions are welcome, mainly i would like the while loop sorted and then if anyone has any suggestions on how to lay it out, would be greatly appreciated 
EDIT: Just realised i was incrementing the count1, corrected, now it displays the first game in my database over and over, any help? Also, the way im doing it to decide games per 'row' there are 14 games in my DB atm, and its displaying 3 per 'row' so i have 12 games displaying(Well i would, if the links wern't all the same... So should i like round the number? Just looking at php.net at the rounding thing, how would i round the number upwards, because i dont want it to ever round down...?
Oscardog
So i went for 4 DIVs using a UL. Here is my code, i had to use task manager to close IE as it was stuck in a loop XD
Code: Select all
<?php $result = mysql_query("SELECT * FROM games");
$gamecount = mysql_num_rows($result);
$result2 = mysql_query("SELECT * FROM games ORDER BY title ASC");
$row = mysql_fetch_array($result2);
$gamesperrow = $gamecount / 5;
$count1 = 0;
$count2 = 0;
$count3 = 0;
$count4 = 0;
?>
<div style="float:left; width: 146px; font-size: 12px;">
<ul>
<?php while($count1 <= $gamesperrow) {
echo "<li><a href=\"playgame.php?game=" . $row['title'] . "\">" . $row['title'] . "</a></li>";
$count1++;
} ?>
</ul>
</div>
<div style="float:left; width: 146px; font-size: 12px;">
<ul>
<?php while($count2 <= $gamesperrow) {
echo "<li><a href=\"playgame.php?game=" . $row['title'] . "\">" . $row['title'] . "</a></li>";
$count2++;
} ?>
</ul>
</div>
<div style="float:right; width: 146px; font-size: 12px;">
<ul>
<?php while($count3 <= $gamesperrow) {
echo "<li><a href=\"playgame.php?game=" . $row['title'] . "\">" . $row['title'] . "</a></li>";
$count3++;
} ?>
</ul>
</div>
<div style="float:right; width: 146px; font-size: 12px;">
<ul>
<?php while($count4<= $gamesperrow) {
echo "<li><a href=\"playgame.php?game=" . $row['title'] . "\">" . $row['title'] . "</a></li>";
$count4++;
} ?>
</ul>
</div>EDIT: Just realised i was incrementing the count1, corrected, now it displays the first game in my database over and over, any help? Also, the way im doing it to decide games per 'row' there are 14 games in my DB atm, and its displaying 3 per 'row' so i have 12 games displaying(Well i would, if the links wern't all the same... So should i like round the number? Just looking at php.net at the rounding thing, how would i round the number upwards, because i dont want it to ever round down...?
Oscardog