echo '<div>';
while ($row=mysql_fetch_assoc($result))
{
if ($row['Course']!=$old_id)
{
$old_id=$row['Course'];
echo '</div>
<div class="sectitle">'.$row['Course'].'</div>
<div style="width:100%;float:left">';
}
if ($row['Approved']==1)
{
$coursedate=date("M Y", strtotime($row['Submitted']));
echo '<div class="nbutton">
<ul>
<li><strong><a target="_new" href="' . $row['AssignmentURL'] . '">' . $row['URL'] . '</a></strong></li>
<li>Instructor: ' . $row['LastName'] . ', ' . $row['FirstName'] . '</li>
<li>Book: '.$row['TextBook'].'</li>
<li>Submitted: '.$coursedate.' </li>
</ul>
</div>';
}
}
echo '</div>';
I’m learning PHP and wrote this in a hurry. Now that I’m understanding more about how loops work, I’m trying to come back to this and reformat it.
The $row contains a value for the Course which is something like ESL 1010 or ENGL 1010, and it’s a standard value for each entry. How can I structure my looping so that it uses something that includes this method I am familiar with:
$courses=array_unique($row['Course'])
foreach ($courses as $course)
{... This is where I get lost.
Sorry if this is a really simple fix. I just can’t seem to wrap my brain around it.
Now
$coursesis an array holding all the courses, you have extracted the data from the MySQL result set and stored it in an array. Do with it whatever you want now.If possible you should avoid doing this however, as it takes longer and uses more memory than iterating through the result set a row at a time.