I need to better sort data displayed on a php page.
Right now my code is
<?php
$db->select_db(mydbname);
$query = "SELECT * FROM resources";
$result = $db->query($query);
$num_results = $result->num_rows;
for ($i=0; $i <$num_results; $i++) {
//process results
$row = $result->fetch_assoc();
echo "<tr>
<td><a href=".($row['url']).">".($row['name'])."</a></td>
<td>".($row['type'])."</td>
<td>".($row['name'])."</td>
</tr>";
}
?>
In the database I have in the "type" field 7 different categories (manufacturer, product, colour, etc.). I'd like to have something like this:
MANUFACTURER
all the records from the db listed by manufacturer
COLOUR
all the records from the db listed by manufacturer
I am not quite sure how to do this efficiently without cutting and pasting the same code under each heading. Right now I have
MANUFACTURER
<?php
$db->select_db(mydbname);
$query = "SELECT * FROM resources WHERE type='Manufacturer";
$result = $db->query($query);
$num_results = $result->num_rows;
for ($i=0; $i <$num_results; $i++) {
//process results
$row = $result->fetch_assoc();
echo "<tr>
<td><a href=".($row['url']).">".($row['name'])."</a></td>
<td>".($row['type'])."</td>
<td>".($row['name'])."</td>
</tr>";
}
?>
COLOUR
<?php
$db->select_db(mydbname);
$query = "SELECT * FROM resources WHERE type='colour";
$result = $db->query($query);
$num_results = $result->num_rows;
for ($i=0; $i <$num_results; $i++) {
//process results
$row = $result->fetch_assoc();
echo "<tr>
<td><a href=".($row['url']).">".($row['name'])."</a></td>
<td>".($row['type'])."</td>
<td>".($row['name'])."</td>
</tr>";
}
?>
etc.
any tips/ ideas?
Thanks ever so mcuh