我正在尝试从mysql 'ptb_stats‘中的一个表中提取信息。这是通过“user_id”特定拉取的,以便网站的每个成员只能看到他们的统计数据。
到目前为止,所发生的一切都是我在页面上得到了回显的图像,而正在提取的信息只是说数组?
我哪里出了问题,有什么建议吗?
谢谢
这是函数:
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;
}这是fetch数组:
<?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
}
?>发布于 2012-10-21 18:45:23
$stats是一个包含所有结果的数组。您需要定义要像这样显示的值:
<?php echo $stats['location']; ?>此外,你应该这样写你的代码:
<?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_ASSOC) http://php.net/manual/fr/function.mysql-fetch-assoc.php
https://stackoverflow.com/questions/12997088
复制相似问题