2014-02-14 45 views
0

我在使用PHP顯示錶格時遇到問題。我已經安裝了shortcode exec php插件。如何在PHP中顯示錶格中的數據

這是代碼我做:

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>"; 

      } 
     } 

我想知道我怎麼能出表中的數據進行排序?任何表的代碼我嘗試似乎並沒有顯示在所有..

+0

您是否嘗試在SQL查詢中進行排序? –

回答

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

陣列在PHP排序 http://us1.php.net/manual/en/function.sort.php

+0

謝謝!這有幫助 –

0

簡單地echo HTML表格標記,像這樣:

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>"; 
+0

我用這個,但使用mysql_fetch_array($ raw_results)){改爲。有另一種方法嗎?或者我必須使用mysqli_fetch_array($ result))? –

+0

是的,你可以使用mysqli_fetch_assoc – Jonathan

0
<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>"; 
0

您需要連接數據庫,然後將數據提取到數據庫中

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>"; 
相關問題