Hi i have made this code to display the most popular games on my site. <? ## # AV ARCADE v3 # popular.php # Loads the most popular games/media module ## $sql = mysql_query("SELECT * FROM ava_games WHERE published=1 ORDER BY hits desc LIMIT 10"); while($row = mysql_fetch_array($sql)) { $abcd= $row['name']; $abcd = str_replace (" ", "-", $abcd); if ($seo_on == 0) { $url = 'games/images'.$row['id'].''; } else { $url = 'view/'.$row['image'].'/'.$abcd.'.png'; } ?> <table border = 1> <tr> <td> <? echo ' <a href="'.$site_url.'/'.$url.'">'.$row['name'].'</a><br>'; ?> </td> </tr> <tr> <td> <? echo '<img src="'.$row['image'].'" width="'.$image_width.'" height="'.$image_height.'" alt="" />'; ?> </td> </tr> </table> <? } ?> Code (markup): however the output displays 10 results all in separate tables...I want it to display all results in the same table, with the images all in line on one row and the title underneath the relevant thumbnail.. any ideas??? i would appreciate your help as am a bit of a novice with PHP
no big deal that's pretty good work, you didn't end your while loop. EDIT: the <table> needs to be outside the while loop.
something more like: <table border = 1> <? $sql = mysql_query("SELECT * FROM ava_games WHERE published=1 ORDER BY hits desc LIMIT 10"); while($row = mysql_fetch_array($sql)) { $abcd= $row['name']; $abcd = str_replace (" ", "-", $abcd); if ($seo_on == 0) { $url = 'games/images'.$row['id'].''; } else { $url = 'view/'.$row['image'].'/'.$abcd.'.png'; } ?> <tr> <td> <? echo ' <a href="'.$site_url.'/'.$url.'">'.$row['name'].'</a><br>'; ?> </td> </tr> <tr> <td> <? echo '<img src="'.$row['image'].'" width="'.$image_width.'" height="'.$image_height.'" alt="" />'; ?> </td> </tr> <? } ?> </table> PHP: the difference, as I mentioned above, is that the table is moved outside the loop.
cool, glad to hear it. I wasn't 100% sure myself, but I thought it should work. Still may need some work if you copy and pasted my code, it was meant to be an example. well have a good holiday EDIT: you may also try a nested table, that might give you more flexibility in your html