2012-10-21 48 views
0

我想從mysql'ptb_stats'中的表中獲取信息。這是通過特定的'user_id'拉動的,這樣每個站點的成員只能看到他們的統計信息。用mysql提取數組顯示信息?

到目前爲止一切事情是我得到的圖像呼應」的頁面上,並被拉信息只是說數組?

任何建議在那裏我去錯了嗎?

感謝

這是函數:

function get_stats() { 
      global $connection; 
      global $_SESSION; 
      $query = "SELECT s.location, s.nationality, s.hobbies, s.role, s.friends, s.height, s.weight 
         FROM ptb_stats s 
         WHERE user_id = \'$profile_id\'"; 



         $stats_set = mysql_query($query, $connection); 
      confirm_query($query, $connection); 
      return $stats_set; 
     } 

這是獲取數組:

<?php 
     $stats_set = get_stats(); 

     while ($stats = mysql_fetch_array($stats_set)) { 


      ?> 
    <table width="100%" border="0"> 
    <tr> 
    <td width="13%"><?php echo "<img width=40px heigh=34px src=\"assets/img/icons/stats.png\"/>" ?></td> 
     <td width="25%"><?php echo " $stats"?> </td> 
     <td width="13%"><?php echo "<img width=40px heigh=34px src=\"assets/img/icons/stats.png\"/>" ?></td> 
     <td width="25%"><?php echo " $stats"?> </td> 
     <td width="13%"><?php echo "<img width=40px heigh=34px src=\"assets/img/icons/stats.png\"/>" ?></td> 
     <td width="20%"><?php echo " $stats"?> </td> 
     </tr> 
     <tr> 
     <td height="36"><?php echo "<img width=40px heigh=34px src=\"assets/img/icons/stats.png\"/>" ?></td> 
     <td><?php echo " $stats"?> </td> 
     <td><?php echo "<img width=40px heigh=34px src=\"assets/img/icons/stats.png\"/>" ?></td> 
     <td><?php echo " $stats"?> </td> 
     <td><?php echo "<img width=40px heigh=34px src=\"assets/img/icons/stats.png\"/>" ?></td> 
     <td><?php echo " $stats"?> </td> 
     </tr> 
     </table> 
<?php 
     } 

     ?> 
+0

你沒有通過$ profile_id getStats函數 – Venu

+0

好的抱歉,我是新來的SQL。我怎麼做? –

+0

和你總是呼應<?php回聲「$ stats」?>而不是<?php echo $ stats ['location']?>等 – Venu

回答

1

$ stats是一個包含所有結果的數組。您需要定義要顯示這樣的哪些值:

<?php echo $stats['location']; ?> 

Futhermore,你應該寫你的代碼,像這樣:

<?php 
    $stats_set = get_stats(); 
    while ($stats = mysql_fetch_assoc($stats_set)) : 
?> 

<table width="100%" border="0"> 
<tr> 
    <td width="13%"><?php echo $stats['location']; ?></td> 
</tr> 
</table> 

<?php endwhile; ?> 

編輯

您需要使用mysql_fetch_assoc而不是mysql_fetch_array(或指定MYSQL_ASSOChttp://php.net/manual/fr/function.mysql-fetch-assoc.php

+0

沒有工作:(仍然得到相同的錯誤:警告:mysql_fetch_assoc()期望參數1是資源,/應用程序中給出的布爾值/XAMPP/xamppfiles/htdocs/PTB1/includes/mod_profile/mod_profile.php 285行 –

+0

上面的代碼是正確的,你有一個SQL請求問題:連接錯誤,sql語法錯誤,....什麼是confirm_query?使用檢查錯誤mysql_error函數後,你的mysql_query函數:http://php.net/manual/fr/function.mysql-error.php – sdespont

+0

確認查詢是:$ stats_set –