Stefbug Posted November 6, 2006 Share Posted November 6, 2006 Hi,I've been trying to work this one out for ages.I am calling data from a database, and displaying it using a while loop:[code]<?phpwhile($row = mysql_fetch_array($query, MYSQL_ASSOC)) { ?> <table><tr><td width="320px"><a href="<?php echo $row['img_url'] ?>" target="_blank"><img src="<?php echo $row['img_url']; ?>" height="200" /></a></td></tr><tr class="submain"> <td width="150px"><?php echo $row['full_name']; ?></td></tr><tr class="submain"><td width="150px"><?php echo $row['description'];?></td></tr><?php }?></table>[/code]This works just fine, and displays a table that has one record per row (each record has 3 pieces of data: img_url, full_name and description that display one under another):-----------|record 1 | -----------|record 2 |-----------etc.However I would like to be able to display this data in a table like this:------------------------------- |record 1 | record 2 | record 3|------------------------------- |record 4 | record 5 | record 6| -------------------------------etc.Any help you could offer would be most appreciated.Thanks in advance.Stef Link to comment https://forums.phpfreaks.com/topic/26308-how-to-display-three-different-records-in-one-row/ Share on other sites More sharing options...
Kelset Posted November 6, 2006 Share Posted November 6, 2006 Not sure what you are looking for here, do you want all the information in one row for each record? The code above putsthe information into three rows. I a very new to PHP but this is something that I might do, code is not tested.[code]<?php//Start row count at 0$row_count = 0;//Start your table echo"<TABLE border ='1'><TR>\r";while($row = mysql_fetch_array($query, MYSQL_ASSOC)) { //Check row_count to see if there should be a new table row made or and col. if ($row_count < 2) { //See if there are no more records, if not put in the blank col. if ($row['img_url'] == "") { echo "<td></td>\r"; }else{ echo "<td width=\"320px\"><a href=\"".$row['img_url']>"\" target=\"_blank\"><img src=\"">$row['img_url']."\" height=\"200\"/></a></td>"; echo "<td width=\"150px\">".$row['full_name']."</td>"; echo "<td width=\"150px\">".$row['description']."</td>"; } //Increment row_count by 1 $row_count++; }else{ if ($row['img_url'] == "") { echo "<td></td></tr><tr>"; }else{ echo "<td width=\"320px\"><a href=\"".$row['img_url']>"\" target=\"_blank\"><img src=\"">$row['img_url']."\" height=\"200\"/></a></td>"; echo "<td width=\"150px\">".$row['full_name']."</td>"; echo "<td width=\"150px\">".$row['description']."</td>"; echo"</TR><tr>\r"; } // $row_count = 0; }}?>[/code]Hope that helps you out in some wayCheers!Stephen Link to comment https://forums.phpfreaks.com/topic/26308-how-to-display-three-different-records-in-one-row/#findComment-120292 Share on other sites More sharing options...
Stefbug Posted November 6, 2006 Author Share Posted November 6, 2006 That helped me a great deal. I have altered the code you gave me slightly and been able to get what I needed.Thank you very much.Stef Link to comment https://forums.phpfreaks.com/topic/26308-how-to-display-three-different-records-in-one-row/#findComment-120318 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.