Stephen Jackson Stephen Jackson - 3 months ago 8
HTML Question

query results and loop them into a table by catagory

I'm trying to query my products table;

+-------------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(50) | NO | | NULL | |
| make | varchar(50) | NO | | NULL | |
| email | varchar(200) | NO | | NULL | |
| catagory | longtext | NO | | NULL | |
+-------------------+--------------+------+-----+---------+----------------+


i want to query the database and echo the results in a table like so, i want it to echo the catagory name then echo all the which will contain the name, make and some other details etc..

I want to show it like so;

Catagory:
name name name name
-------------------------------------
Catagory:
name name name name
-------------------------------------
Catagory:
name name name name
-------------------------------------
Catagory:
name name name name
-------------------------------------


where each name is a different product in the product table. Not sure where too look and what to search for.

Answer
**Check this**

$get_query="select * from products";
@$show_pro=mysqli_query($conn,$get_query);

echo '<div id="show_table" height:400px;">';
echo '<table id="show" border="1" bordercolor="#000000">
        <tr>
            <th> ID </th>
            <th> Name </th>
            <th> Make</th>
            <th> Email</th>
            <th> Category </th> 
        </tr>';

while($row_pro = mysqli_fetch_array($show_pro, MYSQLI_BOTH))
{
    $id = $row_pro['id'];
    $name = $row_pro['name'];
    $make= $row_pro['make'];
    $email= $row_pro['email'];
    $category = $row_pro['category'];


    echo '

        <tr>
        <td width="50" >"'.$id.'"</td>
        <td width="50">"'.$name.'"</td>
        <td width="50">"'.$make.'"</td>
        <td width="50">"'.$email.'"</td>
        <td width="50">"'.$category.'"</td>
        </tr>



    ';

}
echo'</table>';
echo '</div>';
Comments