Jump to content

[SOLVED] while loop help


ngreenwood6

Recommended Posts

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


$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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.