使用php显示数据库结果时遇到问题
我已经用问题注释了我的代码,对解决这个问题有什么建议吗?我已经坚持了几个小时了使用php显示数据库结果时遇到问题,php,mysql,Php,Mysql,我已经用问题注释了我的代码,对解决这个问题有什么建议吗?我已经坚持了几个小时了 <?php include("header.php"); $inv = mysql_query("SELECT `item_id` FROM `user_items` WHERE `user_id`='".$_SESSION['uid']."'") or die(mysql_error()); $linv = mysql_fetch_array($inv); //Need to display all ite
<?php
include("header.php");
$inv = mysql_query("SELECT `item_id` FROM `user_items` WHERE `user_id`='".$_SESSION['uid']."'") or die(mysql_error());
$linv = mysql_fetch_array($inv);
//Need to display all item_id's from the user_items table where the user_id field = $_SESSION['uid'] (or 1 for testing purposes.)
//For some reason, every foreach and while loop method i have tried is giing me false data (1,1). The right data should be: 1, 4.
//The database table contains 3 columns: slot_id, user_id, item_id.
//Those columns contain the following data: 1 1 1
// 2 2 4
// 3 1 4
//surely this should return $linv as an array containing the values 1 and 4? What's going on?
}
include("footer.php");
?>
更改
$linv=mysql\u fetch\u数组($inv);
while(列表($key,$value)=每个($linv))
{
回声(价值);
}
此查询是否正在运行?因为我无法在图片中看到db连接对象。同时停止使用mysql,它们已被弃用。使用mysqli.*
或PDO
。是否尝试在MySQL服务器中手动运行构造的查询?更新的代码:回显“1 1”。:当我直接在sql提示符或phpymyadmin中运行查询时,它会返回我想要的两个字段。我想这只是我展示mysql_fetch_assoc数据的方式的一个问题。我知道它已经贬值,但它是我唯一知道如何使用的。PHP mysql PDO类,你可以尝试使用它,看看你是否喜欢它,谢谢你的工作!你能解释一下原因吗我做错了什么?好的,我会用问题的细节更新答案