How to Echo Results in a Two-column Table

41 views
Skip to first unread message

bipin.pndey

unread,
Aug 23, 2014, 7:39:29 AM8/23/14
to xamp...@googlegroups.com

The code below selects all of the categories in my database, counts how many products are available for each category, and echoes the results in a single column, in an order which I control with a database table column called catorder. Here's how the results look:

All Apparel (6)
Children's Apparel (2)
Men's Apparel (2)
Women's Apparel (2)
All Health and Beauty (15)
Accessories (5)
Cosmetics (5)
Fragrances (5)

I would like to display these results differently. I want to:

1) separate related groups of categories and cap them with a heading, like this:

Apparel

All Apparel (6)
Children's Apparel (2)
Men's Apparel (2)
Women's Apparel (2)

Health and Beauty

All Health and Beauty (15)
Accessories (5)
Cosmetics (5)
Fragrances (5)

2) And I want the results to be displayed in a table with two columns.

Can anyone help, please? I don't know how to do this at all.

Ahmed Khan

unread,
Dec 3, 2015, 9:36:14 AM12/3/15
to PHP Developers' Group
You can use table for this like:

 <table class="table table-striped table-bordered table-responsive table-hover">
    <thead>
      <tr>
        <th>Name</th>
        <th>Union</th>
        <th>Vote</th>
      </tr>
    </thead>
    <tbody>
        <?php
        include 'connection.php';
  
  $query = "SELECT vote.elc_id,vote.area,vote.counts,electrol.name FROM vote INNER JOIN electrol ON vote.elc_id=electrol.elc_id;";
  $conn = OpenCon();
  
    $result = $conn->query($query);
    if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc())
    {
        echo  "<tr><td>".$row['name']."</td><td>".$row['area']."</td><td>".$row['counts']."</td></tr>";
        
    }
       

    
    }
    
 else {
        echo $conn->error;
         
    }
        ?>
      
    </tbody>
  </table>

I was also using tables to separate it.
Reply all
Reply to author
Forward
0 new messages