Search code examples
phphtmlmysqltabular

How to display data in tables in PHP


I have a problem with showing tables in PHP. I have installed shortcode exec php plugin.

This is the code I have done:

if(mysql_num_rows($raw_results) > 0){ 

            while($results = mysql_fetch_array($raw_results)){

                echo "<p><h3>".$results['id']."</h3>"."Student Name :".$results['name']."    </p>" . "</br>";
                echo "Age : ".$results['age']." Years old.</br>";
                echo "Course : ".$results['course']."</br>";
                echo "Gender : ".$results['gender']."</br></br>";
                echo "<HR>";

            }
        }

May I know how I can sort the data out in tables? Any table codes I try doesn't seem to display at all..


Solution

  • <table>
    <tr>
        <td>Student name</td>
        <td>Age</td>
        <td>Course</td>
        <td>Gender</td>
    </tr>
    <?php
    if(mysql_num_rows($raw_results) > 0){ 
            while($results = mysql_fetch_array($raw_results)){
                echo "<tr><td>".$results['id']."</td>";
                echo "<td>".$results['age']."</td>";
                echo "<td>".$results['course']."</td>";
                echo "<td>".$results['gender']."</td></tr>";
            }
        }
    ?>
    </table>
    

    Array sorting in php https://www.php.net/manual/en/function.sort.php