Page: http://youronlinemovies.net/process.php?genre=action/adventure Aim: To pull data from the database, 5 images per row, unlimited rows. Code: <table bgcolor="#f2f8f8" width="100%" align="center" style="border-bottom:2px solid #414141;border-left:2px solid #414141;border-top:2px solid #414141;border-right:2px solid #414141;"><tr> <?php if($_GET['genre']) { $genre = str_replace('%20','',$_GET['genre']); $sql = "SELECT * FROM `films` WHERE `genre` = '".$genre."' ORDER BY `views` DESC"; $res = mysql_query($sql); $rowcount = 0; while($new_row = mysql_fetch_assoc($res)) { $rowcount++; if ($rowcount == 5) { echo "</tr><tr>"; } echo "<td align='center' style='padding:20px;'><p style='font-size:12px'><a href='http://youronlinemovies.net/preview.php?id=".$new_row['id']."' title='".$new_row['title']."'>".$new_row['title']."<br><img src='http://www.youronlinemovies.net/includes/public/images/movies/".$new_row['img']."' width='90px' height='119px' style='border:2px solid #414141;'></a><br>Views:<font color=red> ".$new_row['views']."</font></P></td>"; } } ?> </table><br /><br /> PHP: I'm not much good with PHP/SQL but i've told it to extract 5 then add a new row. But as you can see, it's messed up. Thanks in advance Scott
Because you have a few things in the wrong place and need to add a few things. <?php echo '<table bgcolor="#f2f8f8" width="100%" align="center" style="border-bottom:2px solid #414141;border-left:2px solid #414141;border-top:2px solid #414141;border-right:2px solid #414141;"> <tr>'; if ($_GET['genre']) { $genre = str_replace('%20', '', $_GET['genre']); $sql = "SELECT * FROM `films` WHERE `genre` = '" . $genre . "' ORDER BY `views` DESC"; $res = mysql_query($sql); $rowcount = 0; while ($new_row = mysql_fetch_assoc($res)) { $rowcount++; echo "<td align='center' style='padding:20px;'><p style='font-size:12px'><a href='http://youronlinemovies.net/preview.php?id=" . $new_row['id'] . "' title='" . $new_row['title'] . "'>" . $new_row['title'] . "<br><img src='http://www.youronlinemovies.net/includes/public/images/movies/" . $new_row['img'] . "' width='90px' height='119px' style='border:2px solid #414141;'></a><br>Views:<font color=red> " . $new_row['views'] . "</font></P></td>"; if ($rowcount == 5) { echo "</tr><tr>"; $rowcount = 0; } } //clean up the tr just in case we have not printed it yet. if ($rowcount != 0) { echo '</tr>'; } } echo '</table><br /><br />'; ?> PHP: