This is my db structure
Categories table
id title
-----------
1 cars
2 city
3 names
------------
subcategory table
id cat_id title
1 1 BMW
2 1 Kia
3 2 Moscow
4 1 Passat
5 2 London
6 3 John
----------------------
Now Im getting categories and printing with foreach like this:
$myquery = query("Select * From categories"); // These functions only for example
$array = mysql_fetch_array($myquery); // These functions only for example
foreach($array as $cat){
echo $cat['title'];
echo "<br />";
// in here must be again foreach or other loop to print subcats belongs to
// this category id, otuput like this:
// Cars
// -- BMW
// -- KIA
// -- Passat
// City
// -- Moscow and etc...
}
I dont want use new query inside foreach, I want do this with mysql JOIN but i don't know how. Who can help me?