ngreenwood6 Posted December 8, 2008 Share Posted December 8, 2008 I have the following code: while($incomplete_row = mysql_fetch_array($incomplete_results)) { echo "<tr>"; echo "<td>" . $incomplete_row['school'] . "</td>"; echo "</tr>"; echo "<tr>"; echo "<th>Name</th>"; echo "<th>Request</th>"; echo "<th>Classroom</th>"; echo "<th>Date</th>"; echo "<th>Time</th>"; echo "</tr>"; //make the date $date = date("d/m/Y", $incomplete_row['date']); //make the time $time = date("h:i:s A", $incomplete_row['date']); echo "<tr>"; echo "<td>" . $incomplete_row['name'] . "</td>"; echo "<td>" . $incomplete_row['request'] . "</td>"; echo "<td>" . $incomplete_row['classroom'] . "</td>"; echo "<td>" . $date . "</td>"; echo "<td>" . $time . "</td>"; echo "<td><a href=\"view.php?id=" . $incomplete_row['id'] . "\">View</a>"; echo "</tr>"; echo "</table>"; } The problem is that for every entry it makes a whole new table. I want the school name at the top and then the "<th>" and then the listings. can someone please help. Link to comment https://forums.phpfreaks.com/topic/136117-solved-while-loop-help/ Share on other sites More sharing options...
premiso Posted December 8, 2008 Share Posted December 8, 2008 $i=0; while($incomplete_row = mysql_fetch_array($incomplete_results)) { if ($i == 0) { echo "<tr>"; echo "<td>" . $incomplete_row['school'] . "</td>"; echo "</tr>"; echo "<tr>"; echo "<th>Name</th>"; echo "<th>Request</th>"; echo "<th>Classroom</th>"; echo "<th>Date</th>"; echo "<th>Time</th>"; echo "</tr>"; $i++; } //make the date $date = date("d/m/Y", $incomplete_row['date']); //make the time $time = date("h:i:s A", $incomplete_row['date']); echo "<tr>"; echo "<td>" . $incomplete_row['name'] . "</td>"; echo "<td>" . $incomplete_row['request'] . "</td>"; echo "<td>" . $incomplete_row['classroom'] . "</td>"; echo "<td>" . $date . "</td>"; echo "<td>" . $time . "</td>"; echo "<td><a href=\"view.php?id=" . $incomplete_row['id'] . "\">View</a>"; echo "</tr>"; } echo "</table>"; Try that. Link to comment https://forums.phpfreaks.com/topic/136117-solved-while-loop-help/#findComment-709796 Share on other sites More sharing options...
ngreenwood6 Posted December 8, 2008 Author Share Posted December 8, 2008 Thanks for the help. That is really useful. Link to comment https://forums.phpfreaks.com/topic/136117-solved-while-loop-help/#findComment-709830 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.