pocobueno1388 Posted August 26, 2006 Share Posted August 26, 2006 I am trying to creat a script for a store. On this page it will display all the items I have inserted in the database. The rows include the items name, the url for the image, how many are in stock, and the description. On the store page I want it to pull all the items information out and put it into a table. I want the table to make a <tr> for every 4 rows of the table. This is an example of how I want the page setup:[code]Image Image Image Imagename name name namestock stock stock stockImage name Now the 4th item is on the next row.stock [/code]Hopefully that helped a little. I won't ever have enough different items to make another page, so that won't be necesarry.The code I have now makes a new line for every item, like so:[code]Image namestockImage namestockImage namestock[/code]And here is my code so far:[code]<?phpinclude 'header.php';$sql = mysql_query("SELECT * FROM items_store WHERE stock > 0");print '<table border=1 width="80%" align="center" valign="center">';while ($row = mysql_fetch_assoc($sql)){ echo "<td align='center'><img src='$row[image_url]'><br>"; echo "<b>$row[item_name]</b><br>"; echo "<i>$row[description]</i>"; echo "<h3><a href='store.php'>Buy</a></h3></td>";}print '</table>';?>[/code] Link to comment https://forums.phpfreaks.com/topic/18762-displaying-info-from-db-into-table-then-making-rows-solved/ Share on other sites More sharing options...
Barand Posted August 26, 2006 Share Posted August 26, 2006 here's a method using a table[code]<?phpdefine ("NUMCOLS",4);$res = mysql_query("SELECT col1, col2 FROM mytable");$count = 0;echo "<TABLE border=1>";while (list($col1, $col2) = mysql_fetch_row($res)) { if ($count % NUMCOLS == 0) echo "<TR>\n"; # new row echo "<TD>$col1<br>$col2</TD>\n"; $count++; if ($count % NUMCOLS == 0) echo "</TR>\n"; # end row}# end row if not already endedif ($count % NUMCOLS != 0) { while ($count++ % NUMCOLS) echo "<td> </td>"; echo "</TR>\n";}echo "</TABLE>";?>[/code] Link to comment https://forums.phpfreaks.com/topic/18762-displaying-info-from-db-into-table-then-making-rows-solved/#findComment-80936 Share on other sites More sharing options...
pocobueno1388 Posted August 27, 2006 Author Share Posted August 27, 2006 That displays the name of the item and shows the picture...but I am not sure how to get it to display all the other information and in the order I want it. I would prefer if I could keep this part of the code:[code]while ($row = mysql_fetch_assoc($sql)){ echo "<td align='center'><img src='$row[image_url]'><br>"; echo "<b>$row[item_name]</b><br>"; echo "<i>$row[description]</i>"; echo "<h3><a href='store.php'>Buy</a></h3></td>";}[/code]So if that is possible, that is how I would like it, unless you could get the information to display like that with your code. Otherwise your script would work great =) Link to comment https://forums.phpfreaks.com/topic/18762-displaying-info-from-db-into-table-then-making-rows-solved/#findComment-80948 Share on other sites More sharing options...
pocobueno1388 Posted August 27, 2006 Author Share Posted August 27, 2006 Oh, I figured it out by manipulating your script around barand XD Thanks very much. Link to comment https://forums.phpfreaks.com/topic/18762-displaying-info-from-db-into-table-then-making-rows-solved/#findComment-80950 Share on other sites More sharing options...
AdRock Posted August 28, 2006 Share Posted August 28, 2006 I was looking at the example given by Barand and was wandering if it it possible it use a folder full of images instead of pulling image names from a databaseI thought of uding something like this but need to get it to work if possible[code]$picid = 0;........echo "<TD><img src='images/image".$picid.".jpg'></TD>\n";$picid = $picid + 1;[/code]I know this is probably way off but am i on the right lines? Link to comment https://forums.phpfreaks.com/topic/18762-displaying-info-from-db-into-table-then-making-rows-solved/#findComment-81802 Share on other sites More sharing options...
pocobueno1388 Posted August 28, 2006 Author Share Posted August 28, 2006 That sounds like it would work...but I am not sure. Link to comment https://forums.phpfreaks.com/topic/18762-displaying-info-from-db-into-table-then-making-rows-solved/#findComment-81900 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.