2014-02-14 4 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

는 간단히과 같이 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>"; 
관련 문제