didgydont Posted April 27, 2008 Share Posted April 27, 2008 hi all using some of the code in http://www.phpfreaks.com/forums/index.php/topic,87036.0.html i manged to get the row to count but it does not drop down to the new line after three images i echoed the the row count to make sure it was working instead it displays one item then drops down. basicly it does 1 2 3 1 2 3 instead of 123 123 any ideas? <html> <head> <title>OLD WORLD</title> <link rel="stylesheet" type="text/css" href="site.css" /> <body> </head> <body> <?php include("connect.php"); include("toolbar.php"); echo "<h1 ALIGN=\"center\">Old World Chandliers</h1>"; $result = mysql_query("SELECT * FROM stock"); // $result = mysql_query("SELECT * FROM stock WHERE itemnumber='$itemnumber'"); $i=1; while($row = mysql_fetch_array($result)) { $itemnumber = $row['itemnumber']; $name = $row['name']; $image = $row['image']; echo "<table border='0' ALIGN='center' cellpadding='5' cellspacing='0'>"; if ($i==1){echo "<tr>";} echo "<td><a href='http://autolpg.com.au/oldworld/item.php?itemnumber=$itemnumber'><img src='$image' alt='$name' width='200' height='170'></a> <form action='item.php' method='post' width='200'> <input type='hidden' name='itemnumber' value='$itemnumber'> <input type='submit' VALUE='click here for more details' class=namesbtn> </form> row count is $i</td>"; if ($i==3){echo "</tr>"; $i=0; } $i++; echo "</table>"; } ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/103111-solved-table-to-do-new-row-after-3-results/ Share on other sites More sharing options...
didgydont Posted April 27, 2008 Author Share Posted April 27, 2008 worked it out <html> <head> <title>OLD WORLD</title> <link rel="stylesheet" type="text/css" href="site.css" /> <body> </head> <body> <?php include("connect.php"); include("toolbar.php"); echo "<h1 ALIGN=\"center\">Old World Chandliers</h1>"; $result = mysql_query("SELECT * FROM stock"); // $result = mysql_query("SELECT * FROM stock WHERE itemnumber='$itemnumber'"); $i=1; echo "<table border='0' ALIGN='center' cellpadding='5' cellspacing='0'>"; while($row = mysql_fetch_array($result)) { $itemnumber = $row['itemnumber']; $name = $row['name']; $image = $row['image']; if ($i==1){echo "<tr>";} echo "<td><a href='http://autolpg.com.au/oldworld/item.php?itemnumber=$itemnumber'><img src='$image' alt='$name' width='200' height='170'></a> <form action='item.php' method='post' width='200'> <input type='hidden' name='itemnumber' value='$itemnumber'> <input type='submit' VALUE='click here for more details' class=namesbtn> </form> row count is $i</td>"; if ($i==3){echo "</tr>"; $i=0; } $i++; } echo "</table>"; ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/103111-solved-table-to-do-new-row-after-3-results/#findComment-528180 Share on other sites More sharing options...
sasa Posted April 27, 2008 Share Posted April 27, 2008 try <?php ... $i=1; echo "<table border='0' ALIGN='center' cellpadding='5' cellspacing='0'>"; while($row = mysql_fetch_array($result)){ $itemnumber = $row['itemnumber']; $name = $row['name']; $image = $row['image']; echo "<tr>"; echo "<td><a href='http://autolpg.com.au/oldworld/item.php?itemnumber=$itemnumber'><img src='$image' alt='$name' width='200' height='170'></a> <form action='item.php' method='post' width='200'> <input type='hidden' name='itemnumber' value='$itemnumber'> <input type='submit' VALUE='click here for more details' class=namesbtn> </form> row count is $i</td>"; for ($i = 1; $i < 3; $i++){ $row = mysql_fetch_array($result); if ($row){ $itemnumber = $row['itemnumber']; $name = $row['name']; $image = $row['image']; echo "<td><a href='http://autolpg.com.au/oldworld/item.php?itemnumber=$itemnumber'><img src='$image' alt='$name' width='200' height='170'></a> <form action='item.php' method='post' width='200'> <input type='hidden' name='itemnumber' value='$itemnumber'> <input type='submit' VALUE='click here for more details' class=namesbtn> </form> row count is $i</td>"; } else echo '<td> </td>'; } echo "</tr>"; } echo "</table>"; ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/103111-solved-table-to-do-new-row-after-3-results/#findComment-528181 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.