i was unable to place last div in proper way.
my output from database for query:
SELECT a.id, a.name, b.sub_id, b.sub_name FROM cat a, sub_cat b WHERE a.id = b.cat_id
will be:
| id | name | sub_id | sub_name |
| 1 | moblie | 1 | Phone |
| 1 | mobile | 2 | Mobile Phones Accessories |
| 2 | Lifestyle | 3 | Arts |
| 2 | Lifestyle | 4 | Books |
i want to make this structure:
<div id="moblie" class="tab-pane active">
<a href="?cat=1&sub_cat=1">Phones</a>
<a href="?cat=1&sub_cat=2">Mobile Phones Accessories</a>
</div>
<div id="Lifestyle " class="tab-pane">
<a href="?cat=2&sub_cat=3">Arts</a>
<a href="?cat=2&sub_cat=4">Books</a>
</div>
My Original Php Code :
<?php $query = "SELECT a.id, a.name, b.sub_id, b.sub_name FROM cat a, sub_cat b WHERE a.id = b.cat_id";
$result = mysql_query($query);
$i=0;
$a=1;
$b=0;
while($row = mysql_fetch_assoc($result)){
$i++;
if($i == 1){$set = "active";}else{$set = NULL;}
$hre=strtolower(preg_replace("/[^a-zA-Z]+/", "", $row['name']));
while($a == $row['id']){ $a++;?>
<div id="<?=$hre?>" class="tab-pane <?=$set?>">
<?php }?>
<a href="?cat=<?=$row['id']?>&sub_cat=<?=$row['sub_id']?>"><?=$row['sub_name']?></a>
<?php while($b == $row['id']){ $b++;?></div>
<?php }
}?>
Output I am receiving :
<div id="mobilephones" class="tab-pane active">
<a href="?cat=1&sub_cat=1">Mobile Phones</a>
<a href="?cat=1&sub_cat=2">Mobile Phones Accessories</a>
<div id="homelifestyle" class="tab-pane ">
<a href="?cat=2&sub_cat=3">Art - Collectibles - Hobbies</a>
<a href="?cat=2&sub_cat=4">Books - Magazines</a>
</div></div>
My Idea : as it was last while loop how can it understand upcoming value to print div.
I have tried in different ways not not found solution.Please help me out.
Note:I know how to make it with loop quires.but,I want to do it through single mysql query.