Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8592901
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:51:46+00:00 2026-06-11T23:51:46+00:00

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

  • 0
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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T23:51:47+00:00Added an answer on June 11, 2026 at 11:51 pm
    $courses = array();
    while ($row = mysql_fetch_assoc($result)) {
        $courses[] = $row;
    }
    

    Now $courses is 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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

echo '<p class=post><h3>'.$result['title'].'</h3><object class=video width=95% height=55%> <param name=movie value=http://www.youtube.com/v/'.$match[0].'?fs=1&amp;hl=en_US&rel=0> </param><param name=allowFullScreen value=true></param> <param name=allowscriptaccess
echo (<div style=\text-align:center\> . include ('file.php') . </div>\n); I'm not sure why, but whenever
echo '<table>'; echo '<tr>'; $i = ''; while($res = mysql_fetch_assoc($mysqlqry)){ echo '<td><a href='. $res['link']
echo '<img src=data:image/jpg/png/jpeg;base64,' . base64_encode( $row['image'] ) . ' height=150 />'; This is showing
echo $nav gives code like this: <ul> <li class=someclass>sometext <ul> <li class=someclass>sometext</li> <li class=spacer></li>
echo Info: <input type=\text\ name=\titel\> value=\ . $row['titel'] . \> . <br />; Why
echo <img src=.$file. > ; does not display image, while $file points to the
echo a b _c d _e f | sed 's/[ ]*_[a-z]\+//g' The result will
echo '<a onClick=articleDeleteConfirm('. $row[title_$lang].','.$_GET[editPage]).'>'; The main problem is with: $row[title_$lang] , I have to
echo <<<_END <pre> <a href=#home data-rel=dialog data-num=$row[1] data-id=myid>$row[1]</a> </pre> _END; <script> var b =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.