truegilly Posted April 2, 2007 Share Posted April 2, 2007 Hi guys Ive been playing around with this for a while and im becoming confused ??? basically all i want to do is to display the results from my SQL Query and render them in a HTML table but after every third bit of data i want to echo out a <tr> tag to start a new row. I know you guys are bound to know a simple clever way of archiving this !! heres my code... session_start(); require("sapphire_web_dbConnect.php"); $userid = $_SESSION['UserId']; $query = "SELECT VC10_Risk_Id, Risk_Name, Confrimation_Description FROM vc10_risk WHERE RAFPerId = '$userid'"; $result = mysql_query($query); $row = mysql_fetch_row($result); if(mysql_num_rows($result) == 0) { echo "You have not entered any Risks or Issues <B><span class='style4'>$name</span></B><BR>"; } else { echo"<table width='150%' border='1' align='center' class='style1'>"; echo"<tr>"; echo"<td width='11%'><div align='center' class='style2'>Risk No</div></td>"; echo"<td width='19%'><div align='center' class='style2'>Risk Name</div></td>"; echo"<td width='83%'><div align='center' class='style2'>comentary</div></td>"; echo"<tr>"; } echo "<td>".$row[0]."</td>"; echo "<td>".$row[1]."</td>"; echo "<td>".$row[2]."</td>"; echo"<tr>"; echo"</table>"; so far you can see that ive hard coded the <tr> in but is it possible to create a loop that if the position is a multiple of 3 it echo's the <tr> and continues iterating through ? any help is most appreciated Truegilly Link to comment https://forums.phpfreaks.com/topic/45329-table-row-intervals-from-an-array/ Share on other sites More sharing options...
papaface Posted April 2, 2007 Share Posted April 2, 2007 I think if you made a variable named $num and increment it each time the while loops '$num++', and have an IF statement in the which is basically: $num = 0; while (lalalal) { // your table code here if ($num == 3) { echo "<tr>"; $num = 0; } $num++; } Ive probably made a mistake in there, but you get the idea. Link to comment https://forums.phpfreaks.com/topic/45329-table-row-intervals-from-an-array/#findComment-220087 Share on other sites More sharing options...
truegilly Posted April 2, 2007 Author Share Posted April 2, 2007 Thanks man that did the trick !! Truegilly Link to comment https://forums.phpfreaks.com/topic/45329-table-row-intervals-from-an-array/#findComment-220114 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.