hi guys, i want to display 2 or more records per row. no only one. how i can do this? my php code is this: <?php $con = mysql_connect("localhost","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("storedb", $con); $result = mysql_query("SELECT * FROM products ORDER BY price"); ?> <table width="200" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#666666"> <?php while($row = mysql_fetch_assoc($result)) {?> <tr> <td align="center" bgcolor="#FFFFFF"><?php echo $row['product_id'];?></td> </tr> <?php } mysql_close($con); ?> </table> PHP: can anyone help me? thanks in advance
replace mysql_fetch_assoc by mysql_fetch_array and be work <?php $con = mysql_connect("localhost","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("storedb", $con); $result = mysql_query("SELECT * FROM products ORDER BY price"); ?> <table width="200" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#666666"> <?php while($row = mysql_fetch_array($result)) {?> <tr> <td align="center" bgcolor="#FFFFFF"><?php echo $row['product_id'];?></td> </tr> <?php } mysql_close($con); ?> </table> PHP:
Hey, I am not trying to hijack your thread but I think you might be looking for the same answer I am and just did not word your question the same. Here is what I am trying to do: I am using a simple while() loop to print out a list of categories and turn them into links. The format below produces a single column of those links. What I would like to do is have them appear in two columns. Is there anyway to do that without reading them to an array first. I'm not even sure how to make it happen after I read them into it. Is that what you were asking? And can anyone shed some light for either of us.
Ok since I do this so much: <?php $con = mysql_connect("localhost","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("storedb", $con); $result = mysql_query("SELECT * FROM products ORDER BY price"); ?> <table width="200" border="0" align="center" cellpadding="4" cellspacing="1" bgcolor="#666666"><tr> <?php while($row = mysql_fetch_array($result)) { if($i==2){ echo "</tr><tr>"; $i=0;} ?> <td align="center" bgcolor="#FFFFFF"><?php echo $row['product_id'];?></td> <?$i++; } echo "</tr>"; mysql_close($con); ?> </table> Code (markup): Hope that helps all. If not, hit me up via a PM or email me @
Thank you very much! Green rep added. I had to tweak it just a little but your code was sound. It turned a single column into two perfectly.