-2

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    |                |
| category          | longtext     | NO   |     | NULL    |                |
+-------------------+--------------+------+-----+---------+----------------+

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

I want to show it like so;

Category:
name       name       name       name
-------------------------------------
Category:
name       name       name       name
-------------------------------------
Category:
name       name       name       name
-------------------------------------
Category:
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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Stephen Jackson
  • 260
  • 2
  • 6
  • 20
  • 2
    this can be achieved with html tables and a few loops. – Funk Forty Niner Aug 08 '16 at 18:36
  • and maybe some if-statements – developerwjk Aug 08 '16 at 18:38
  • datatables is also one that I've used before (few moons ago). https://datatables.net/ – Funk Forty Niner Aug 08 '16 at 18:41
  • 1
    If your dataset isn't large, or expected to become that way, you can read everything into an array, and then sort or split them based on the category prior to output. – Kevin_Kinsey Aug 08 '16 at 18:47
  • possible duplicate of [Show values from a mySQL database table inside a html table in a page](http://stackoverflow.com/questions/17902483/show-values-from-a-mysql-database-table-inside-a-html-table-in-a-page) – Funk Forty Niner Aug 08 '16 at 18:48
  • its not a duplicate, i'm not trying to just create a simple table with data, i'm trying to group the echo results into categories. as per my above example – Stephen Jackson Aug 08 '16 at 18:54
  • then GROUP them. really, you have to try something. If I post an answer, I might be at it for an hour. I'm leaving the question btw, so you can ping me if you want. Funny how you suddenly come in and comment about the possible dupe though, but nothing else. question's too broad then. – Funk Forty Niner Aug 08 '16 at 18:55
  • i came in on the duplicate because it was an easy reply, the other comments don't relate to my problem apart from the possibility of putting the data into arrays and sorting them that way. but now im looking at how to GROUP the data. – Stephen Jackson Aug 08 '16 at 19:00

1 Answers1

2
**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>';