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 647845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:46:04+00:00 2026-05-13T21:46:04+00:00

Right, so I’ve got a query that looks like this: $bestof_query = SELECT *

  • 0

Right, so I’ve got a query that looks like this:

$bestof_query = "SELECT * FROM physicians p JOIN (awards a, categories c, awardLevels l) ON (a.id = p.id AND c.id = a.category AND l.id = a.level) ORDER BY a.category, a.level ASC ";
$query = mysql_query($bestof_query);

while($result = mysql_fetch_array($query)) {
 extract($result);
 echo "<h3>" . $category . "<h3>";
   foreach($category as $value) {
       echo "<h5>" . $name . "<h5>" . "<p>" . $description . "</p>" . "\r\n";
   }
}

A typical result looks like-

Array (
 [0] => 39  [id] => 1
 [1] => William�B.�Poff [name] => William�B.�Poff
 [2] => 10 South Main Street [address1] => 10 South Main Street
 [3] => Tower A, Suite 1400 [address2] => Tower A, Suite 1400 
 [4] => Jackson [city] => Jackson 
 [5] => VA [state] => VA
 [6] => 24111 [zip] => 24111
 [7] => downtown-jackson [neighborhood] => downtown-jackson
 [8] => 5409837649 [phone] => 5401111111
 [9] => http://www.foo.com [uri] => http://www.foo.com 
 [10] => Foo�Rogers,�PLC [firm] => Foo�Rogers,�PLC
 [11] => 39 
 [12] => 1 [category] => Bankruptcy
 [13] => 1 [level] => 1 
 [14] => 2009 [year] => 2009 
 [15] => 1 
 [16] => Bankruptcy 
 [17] => 1 
 [18] => Platinum [description] => Platinum )

I’m trying to loop through based on the [category] and while the category is equal to Bankruptcy, then output all the results for bankruptcy, then move on to the next category.

Does that make sense? I’ve never been very good with loops so thanks in advance!

What I am hoping for is-

<h3>$category</h3>
<ul>
<li>$name - $description</li>
<li>$name - $description</li>
<li>$name - $description</li>
<li>$name - $description</li>
</ul>

And then iterate to the next category. I think a nested loop, but I’m not sure how to do the nested loop.

  • 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-05-13T21:46:04+00:00Added an answer on May 13, 2026 at 9:46 pm

    You need a simple state machine. This is a way of doing a nested loop without doing a real nested loop. Especially as the data-stream is a single-dimension.

    $category = '';
    while( $result = mysql_fetch_array($query) ) {
        if( $result['category'] != $category ) {
            $category = $result['category'];
            echo "<h3>".$category."</h3>\n";
        }
    
        echo "<h5>".$result['name']."</h5>\n";
        echo "<p>".$result['description']."</p>\n";
    }
    

    It gets more complex if you have markup for each group as a whole, but this is the basic idea. It relies on the fact that that everything in the same category is together, which you achieve with the ORDER BY.

    P.S: don’t use extract(); it pollutes your namespace.

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

Sidebar

Related Questions

Right now I have something in php that looks like this: $count = array_count_values($result);
Right, so here the scenario: I've created a class called DiaryPage that inherites from
Right, i'm new to PHP and mySQL, but i've got a few questions that
Right now, I have a jQuery UI pop-up dialog that reads from an external
Right now my ant task looks like. <javadoc sourcepath=${source} destdir=${doc}> <link href=http://java.sun.com/j2se/1.5.0/docs/api/ /> </javadoc>
Right now I'm doing something like this: RewriteRule ^/?logout(/)?$ logout.php RewriteRule ^/?config(/)?$ config.php I
Right now, I have an enum like this: public enum ReferenceType { Language =
Right now when i do something like this: use strict; use warnings; package My::Test;
Right now when I run this it keeps clicking on the same button every
Right now, I've just some code which fetches the picture from the URL directly.

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.