0

Hi,

I wonder if anyone can help me with a basic MySQL/PHP output problem please.

I have a table called 'Recommendations' which has a small number of fields (id, recom_date, recom_name, recom_status and recom_size).

I want to be able to show the 'recom_status' field as a heading with the other fields lsited below each heading. If the recom_status fields contain only 'Final', 'Draft' and 'Withdrawn' I want the display to look like this

FINAL
name date size
name date size

DRAFT
name date size
name date size

WITHDRAWN
name date size
name date size

I believe that the MySQL is something like:

SELECT * FROM 'Recommendations' ORDER BY 'recom_status', recom_name';

but I don't have a clue how to display this using PHP

Any help will be greatly appreciated

2
Contributors
1
Reply
16
Views
2 Years
Discussion Span
Last Post by gabrielcastillo
0

This should get you started.

<?php
$connection = mysqli_connect('host','username','password','database_name');

$sql = "SELECT * FROM recommendations ORDER BY recom_status, recom_name";

$query = mysqli_query($connection, $sql);

$results = mysql_fetch_assoc($query);

?>
<?php foreach($results as $result): ?>
<h3><?php echo ucfirst($result['recom_status']; ?></h3>
<table>
    <tr>
        <th>Name</th>
        <th>Date</th>
        <th>Size</th>
    </tr>
    <tr>
        <td><?php echo $result['recom_name']; ?> </td>
        <td><?php echo $result['recom_date']; ?></td>
        <td><?php echo $result['recom_size']; ?></td>
    </tr>
</table>
<?php endforeach; ?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.