php - result of while loop showing differently -


in first page of site user suppose see categories, under each category there sub-categories. fetching these categories , sub-categoires database. there 2 tables in database called "category" , "subcategory" , have tried merge these 2 tables. ouput should this

the expected ouput

but getting ouput

the ouput getting

here code

<?php       $host="localhost";     $user="root";     $pass="";     $db="doc";      $conn=mysqli_connect($host,$user,$pass,$db);      $show=mysqli_query($conn,"select distinct a.id, a.category_name, b.subcat_name, b.cat_name         category a, subcategory b         a.category_name = b.cat_name");  ?>  <html lang="en"> <head>   <title>home</title>   <meta charset="utf-8">   <meta name="viewport" content="width=device-width, initial-scale=1">   <link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css">   <link href="css/custom.css" rel="stylesheet">   <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">   <script src="bootstrap/bootstrap.min.js"></script>   <script src="js/jquery.min.js"></script> </head> <body>             <div class="col-lg-3 sidebar">               <?php         while($showsub = mysqli_fetch_assoc($show)) { ?>                  <ul>                     <li><i class="fa fa-cube"></i><a href="category.php?id=<?php echo $showsub['id']; ?>"><?php echo $showsub['category_name']; ?></a>                         <ul style="list-style-type:circle">                             <li><?php echo $showsub['subcat_name']; ?></li>                          </ul>                     </li>                 </ul>             <?php             }; ?>             </div> </body> </html> 

i stuck here last 2 days.

<?php  $host="localhost"; $user="root"; $pass=""; $db="doc";  $conn=mysqli_connect($host,$user,$pass,$db); ?>  <html lang="en"> <head>   <title>home</title>   <meta charset="utf-8">   <meta name="viewport" content="width=device-width, initial-scale=1">   <link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.4.0/css/font-awesome.min.css">   <link href="css/custom.css" rel="stylesheet">   <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">   <script src="bootstrap/bootstrap.min.js"></script>   <script src="js/jquery.min.js"></script> </head> <body>     <div class="col-lg-3 sidebar">            <?php         $cat = mysqli_query($conn,"select distinct id, category_name category");         while($rowcat = mysqli_fetch_assoc($cat))          {          $catname = $rowcat['category_name'];         ?>             <ul>                 <li>                     <i class="fa fa-cube"></i>                     <a href="category.php?id=<?php echo $rowcat['id']; ?>">                         <?php echo $rowcat['category_name']; ?>                     </a>                  <?php                 $subcat = mysqli_query($conn,"select * subcategory cat_name='$catname'");                 while($rowsubcat = mysqli_fetch_assoc($subcat))                 {?>                 <ul style="list-style-type:circle">                     <li><?php echo $rowsubcat['subcat_name']; ?></li>                 </ul>                 <?php }?>                  </li>             </ul>         <?php         }?>      </div> </body> </html> 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -