PHP回显结果成表[关闭]

PHP回显结果成表[关闭]

问题描述:

I am struggling to put the data that is pulled from my database into a table layout.

This is the echo result:

echo "<p><h3>".$results['ID Number']."</h3>".$results['id_number']."</p>";
            echo "<p><h3>".$results['Card Status']."</h3>".$results['card_status']."</p>";
            echo "<p><h3>".$results['Full Name']."</h3>".$results['full_name']."</p>";
            echo "<p><h3>".$results['DBS/CRB Number']."</h3>".$results['dbs_number']."</p>";
            echo "<p><h3>".$results['Job Title']."</h3>".$results['job_title']."</p>";
            echo "<p><h3>".$results['Card Start Date']."</h3>".$results['card_start_date']."</p>";
            echo "<p><h3>".$results['Card Expiry']."</h3>".$results['card_expiry_date']."</p>";
            echo "<img src='photos/".$results['photo_name']."'>";

Please can someone help me, its driving me crazy, also the Name of the result isn't showing, e.g. 'ID Number' as a title then 'id_number' result.

or is there an easier way to show all the data from the record rather than having multiple echo's

I have a search box to find a record matching the id_number and then the data connected to a id_number is then shown

Well I dont think there was any help needed , still for the sake of your blockade use this as

echo "<table><tr><td><h3>ID Number</h3></td><td>".$results['id_number']."</td></tr>";
                echo "<tr><td><h3>Card Status</h3></td><td>".$results['card_status']."</td></tr>";
                echo "<tr><td><h3>Full Name</h3></td><td>".$results['full_name']."</td></tr>";
                echo "<tr><td><h3>DBS/CRB Number</h3></td><td>".$results['dbs_number']."</td></tr>";
                echo "<tr><td><h3>Job Title</h3></td><td>".$results['job_title']."</td></tr>";
                echo "<tr><td><h3>Card Start Date</h3></td><td>".$results['card_start_date']."</td></tr>";
                echo "<tr><td><h3>Card Expiry</h3></td><td>".$results['card_expiry_date']."</td></tr>";
                echo "<tr><td></td><td><img src='photos/".$results['photo_name']."'></td></tr></table>";

I'd personally store those into an array and loop over it.

Something like this:

<?php
$array = array();

$array[] = $results['ID Number'] . ' ' . $results['id_number'];
//And so on until all the values you want are in the array.
//You could potentially use a loop for this too, depending on your code

echo '<table>';

foreach($array as $value){
    echo '<tr>';
    echo '<td> $value </td>';
    echo '</tr>;

}

echo '</table>';

As for the name of the result not showing up. It's hard to pin point that out without looking at the rest of the code.