ai didi

php - 在 php 中解析 MySQL 结果时遇到问题

转载 作者:行者123 更新时间:2023-11-29 04:31:14 24 4
gpt4 key购买 nike

我正在尝试从数据库中提取一些结果,但我想我今天有点脑残。

$castquery = "SELECT * FROM cast " .
"WHERE player_id = '" . $userid ."' ";
$castresult = mysql_query($castquery) or die(mysql_error());
$castrow = mysql_fetch_array($castresult);

...

foreach($castrow['cast_id'] as $caster) 
{
echo "<p>";
if ($caster['avatar_url']!='') echo "<img src=\"".$caster['avatar_url']."\" alt=\"".$caster['name']."\">";
echo "<a href=\"?edit=".$caster['cast_id']."\">".$caster['name']."</a></p>";
}

当然,我在这里忽略了一些明显的东西。

最佳答案

不确定您的数据库结构是什么,但是 $castrow['cast_id'] 是单个字段,而不是数组。你的意思可能是:

while ( $castrow = mysql_fetch_array($castresult) ) {
// use $castrow array here
}

代替你的foreach

关于php - 在 php 中解析 MySQL 结果时遇到问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2128304/

24 4 0
文章推荐: mysql - 无法使用vbscript连接到Mysql
文章推荐: sql - 返回在另一个表中具有匹配记录的行
文章推荐: php - MySQL 表中的斜线,但使用 PDO 和参数化查询。这是怎么回事?
文章推荐: mysql - 第 462 行的 fatal error : Maximum execution time of 60 seconds exceeded in\doctrine\lib\Doctrine\Collection. php
行者123
个人简介

我是一名优秀的程序员,十分优秀!

滴滴打车优惠券免费领取
滴滴打车优惠券
全站热门文章
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com