Note that there are some explanatory texts on larger screens.

plurals
  1. POLooping through a JOIN'ed MySQL Associative Array
    primarykey
    data
    text
    <p>Right, so I've got a query that looks like this:</p> <pre><code>$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 "&lt;h3&gt;" . $category . "&lt;h3&gt;"; foreach($category as $value) { echo "&lt;h5&gt;" . $name . "&lt;h5&gt;" . "&lt;p&gt;" . $description . "&lt;/p&gt;" . "\r\n"; } } </code></pre> <p>A typical result looks like-</p> <pre><code>Array ( [0] =&gt; 39 [id] =&gt; 1 [1] =&gt; William�B.�Poff [name] =&gt; William�B.�Poff [2] =&gt; 10 South Main Street [address1] =&gt; 10 South Main Street [3] =&gt; Tower A, Suite 1400 [address2] =&gt; Tower A, Suite 1400 [4] =&gt; Jackson [city] =&gt; Jackson [5] =&gt; VA [state] =&gt; VA [6] =&gt; 24111 [zip] =&gt; 24111 [7] =&gt; downtown-jackson [neighborhood] =&gt; downtown-jackson [8] =&gt; 5409837649 [phone] =&gt; 5401111111 [9] =&gt; http://www.foo.com [uri] =&gt; http://www.foo.com [10] =&gt; Foo�Rogers,�PLC [firm] =&gt; Foo�Rogers,�PLC [11] =&gt; 39 [12] =&gt; 1 [category] =&gt; Bankruptcy [13] =&gt; 1 [level] =&gt; 1 [14] =&gt; 2009 [year] =&gt; 2009 [15] =&gt; 1 [16] =&gt; Bankruptcy [17] =&gt; 1 [18] =&gt; Platinum [description] =&gt; Platinum ) </code></pre> <p>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.</p> <p>Does that make sense? I've never been very good with loops so thanks in advance!</p> <p>What I am hoping for is-</p> <pre><code>&lt;h3&gt;$category&lt;/h3&gt; &lt;ul&gt; &lt;li&gt;$name - $description&lt;/li&gt; &lt;li&gt;$name - $description&lt;/li&gt; &lt;li&gt;$name - $description&lt;/li&gt; &lt;li&gt;$name - $description&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>And then iterate to the next category. I think a nested loop, but I'm not sure how to do the nested loop.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload