I have a table that looks somewhat like this:
CREATE TABLE foobar
(
id INT(6) NOT NULL AUTO_INCREMENT,
category ENUM('Cat1','Cat2','Cat3','Cat4') NOT NULL,
name VARCHAR(255) NOT NULL,
PRIMARY KEY(id),
);
I have one page where all this data is to be displayed like this:
<h3>Cat1</h3>
<ul>
<li>Value1</li>
<li>Value2</li>
</ul>
<h3>Cat2</h3>
<ul>
<li>Value1</li>
<li>Value2</li>
</ul>
...
My question is whether it's more efficient to make one query for each category limiting the result set to one category... SELECT name FROM foobar WHERE category = cat1;
or whether I should get the entire table SELECT category, name FROM foobar;
and then use PHP to process the results and then loop through each category and display its values.
Which is more effcient or is there another way to do this?
Thanks!