Jump to content

mysql_fetch_array Join two table query problem.... HELP PlS!!


StefanRSA

Recommended Posts

Hi... I have a MySql DB with two tables... adcat and adsubcat.

My code is as follow:

$result = mysql_query(
"SELECT * FROM ".$prefix."adcat 
JOIN adsubcat ON adsubcat.catid=adcat.id

ORDER by sortorder,id"
) 
or died("Record NOT Found: ".mysql_error());
?>
<center>
<div id="wrapper">
<?
while ($db = mysql_fetch_array($result)) {
echo "<div id =".$db[div].">".$db[name]."<br><div id=".$db[divsub].">".$db[subname]."</div></div>";
}
?>

  
  <div class="clear"> </div>
</div>
</center>

 

My Problem is that I am trying to put my results in seperate blocks with the adcat.name as heading and then all subnames connected to adcat.name below that...

 

What is happening now, is that I get a block for each line of the joined tables.... Can anybody please help me?

Or let me put it this way...

 

I have two tables. One is categories. The Other is subcategories.

I want to categorize all the subcategories under the categories...

 

Please look at my code and tell me what I am doing wrong. At this moment I have the following:

 

CAT1                      CAT1                        CAT2

CAT1 SUB1              CAT1 SUB2                CAT2 SUB1

 

Instead of:

CAT1                      CAT2

CAT1 SUB1              CAT2 SUB1

CAT1 SUB2

 

Please help....

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.