Domanda

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..

È stato utile?

Soluzione

<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 http://us1.php.net/manual/en/function.sort.php

Altri suggerimenti

Simply echo the html table tags like so:

echo "<table border='1'>
<tr>
<th>Id</th>
<th>Age</th>
<th>Course</th>
<th>Gender</th>
</tr>";

while($row = mysqli_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['id'] . "</td>";
  echo "<td>" . $row['name'] . "</td>";
  echo "<td>" . $row['course'] . "</td>";
  echo "<td>" . $row['age'] . "</td>";
  echo "</tr>";
  }
echo "</table>";
    <table>
        <tr>
        <th>ID</th>
        <th>Student Name</th>
        <th>Age</th>
        <th>Course</th>
        <th>Gender</th>
        </tr>

    while($results = mysql_fetch_array($raw_results)){
            echo "<tr>";
            echo "<td>".$results['id']."</td>";
            echo "<td>".$results['name']."</td>";
            echo "<td>".$results['age']." Years old.</td>";
            echo "<td>".$results['course']."</td>";
            echo "<td>".$results['gender']."</td>";
            echo "</tr>";

        }
    echo "</table>";

you need to connect databse and then fetch data to database

while($results = mysql_fetch_array($row)){
        echo "<tr>";
        echo "<td>".$results['id']."</td>";
        echo "<td>".$results['name']."</td>";
        echo "<td>".$results['age'].".</td>";
        echo "<td>".$results['course']."</td>";
        echo "<td>".$results['gender']."</td>";
        echo "</tr>";
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top