2012-10-21 47 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 –