MySQL Forums
Forum List  »  PHP

SQL SELECT Query Inside Select Query is Not Running Help Me
Posted by: Vicky Mehra
Date: February 07, 2016 09:52AM

Hello Friends i Am creating category and subcategory and i write code in html getting an issue after making it dynamic by using PHP. So, let me tell you what is my issue?.

My issue is that i create category and subcategory design using html.

and my subcategory is inside category you can see it below.

(Category and subcategory code start)


<ul id="css3menu1" class="topmenu">
<?php
$r=$mysqli->query("SELECT * FROM category");

while($row=$r->fetch_assoc()){
extract($row);
?>


<li class="topmenu"><a href="#" style="width:200px;"><span><?php echo $row['category'];?></span></a> (Category)
<ul>
<?php
$r=$mysqli->query("SELECT * FROM subcategory WHERE category='".$category."'");
$count=$r->num_rows;
if($count>0){

while($row=$r->fetch_assoc()){
extract($row);
?>


<li class="subfirst"><a href="#"><?php echo $row['subcategory'];?></a></li> (Subcategory)

<?php
}
}
?>

</ul></li>
<?php

}
?>

</ul>

(Category and subcategory code start)



Please check this code carefully.

first i write select query for showing categories it was running fine all the categories were showing without subcategories because i hadn't write coding for showing subcategories.

but after that when i write code for showing subcategories inside categories than only first category row is fetching i mean only first category is showing with its subcategories and remaining categories are not displaying and fetching from database
.

Options: ReplyQuote


Subject
Written By
Posted
SQL SELECT Query Inside Select Query is Not Running Help Me
February 07, 2016 09:52AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.