Thats a kinda sub-select which I don't think is supported by Mysql. If you havn't got too many rows just do 2 queries instead.
$sql=mysql_query("selecty * from blah blah");
while($row=mysql_fetch_array($sql)){
echo "category here";
$sql2=mysql_query("SELECT * FROM table where subcategory='$row[category]'");
while($row2=mysql_fetch_array($sql2)){
echo "subcategory here";
}
}
This isn't the most efficient way to do it but it's okay if you have a small db.
cheers
allgood2 wrote:
I can\'t seem to figure this out. I have a query that groups data then displays by subcategory. I want the subcategory display like so...
subcategory
item one
item two
subcategory2
item one
etc.
What I get is just the first value under each subcategory or...
sucategory
item one
subcategory2
item one
Here\'s my code, what am I doing wrong....
$category=$category;
$results=mysql_query (\"SELECT * FROM library WHERE category=\\"$category\\" GROUP BY subcategory ORDER BY title\") or die(\"No return for $category\");
while ($row=mysql_fetch_array($results)){
$author = $row[\"author\"];
$title = $row[\"title\"];
$date = $row[\"date\"];
$category = $row[\"category\"];
$subcategory = $row[\"subcategory\"];
$url = $row[\"url\"];
$id = $row[\"id\"];
if($title==\"\")
{
$display_doc .=\"
<div class=\\\"xtrasmallVerticalSpacer\\\"> </div>
\";
}
else
{
$display_doc .=\"
<p class=\\"paraTitle\\">$....