Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You could loop through the entire data set, keeping track of the <code>portfolio_id</code> of each row. Then, each time the <code>portfoio_id</code> changes, start a new list.</p> <p>If I'm understanding correctly, this should help. Here's how you could separate a generic set of images into different unordered lists using <code>group_id</code> to define groups:</p> <pre><code>// select the entire set, group by whichever field defines your groups $result = mysql_query("SELECT image_path FROM portfolio ORDER BY group_id"); // the group_id associated with the currently growing &lt;ul&gt; $current_id = null; while ($row = mysql_fetch_array($result)) { $group_id = $row['group_id']; // the first list if (is_null($current_id)) { $current_id = $group_id; echo "&lt;ul&gt;\n"; } // if a new group_id is encountered, close the list and start a new one elseif ($group_id != $current_id) { $current_id = $group_id; echo "&lt;/ul&gt;\n\n&lt;ul&gt;\n"; } echo "&lt;li&gt;&lt;image src=\"" . $row['image_path'] . "\"&gt;&lt;/li&gt;\n"; } echo "&lt;/ul&gt;\n"; </code></pre> <p>The table looks like this:</p> <pre><code>mysql&gt; SELECT * FROM portfolio; +------------+----------+ | image_path | group_id | +------------+----------+ | a.png | 1 | | b.png | 3 | | c.png | 4 | | d.png | 3 | | e.png | 3 | | f.png | 1 | | g.png | 4 | +------------+----------+ 7 rows in set (0.00 sec) </code></pre> <p>And the output of the above program looks like this:</p> <pre><code>&lt;ul&gt; &lt;li&gt;&lt;image src="a.png"&gt;&lt;/li&gt; &lt;li&gt;&lt;image src="f.png"&gt;&lt;/li&gt; &lt;/ul&gt; &lt;ul&gt; &lt;li&gt;&lt;image src="b.png"&gt;&lt;/li&gt; &lt;li&gt;&lt;image src="d.png"&gt;&lt;/li&gt; &lt;li&gt;&lt;image src="e.png"&gt;&lt;/li&gt; &lt;/ul&gt; &lt;ul&gt; &lt;li&gt;&lt;image src="c.png"&gt;&lt;/li&gt; &lt;li&gt;&lt;image src="g.png"&gt;&lt;/li&gt; &lt;/ul&gt; </code></pre>
 

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