gpt4 book ai didi

php - MySQL 查询返回数千个空结果

转载 作者:行者123 更新时间:2023-11-29 09:06:37 24 4
gpt4 key购买 nike

当我运行第二个查询来选择部门时,它返回我的部门列表,大约有 20 条记录,然后返回数千个空白条目,页面在浏览器中卡住,我做错了什么?

        mysql_select_db("ita", $con);

$results = mysql_query("SELECT * FROM `Colleges`");

$colleges = array();

while($row = mysql_fetch_assoc($results))
{
$colleges[] = array("Name" => $row['Name'], "Value" => $row['Value'], "ID" => $row['CollegeID']);
}

$collegecount = count($colleges);

$depts = array();

$result1 = mysql_query("SELECT * FROM `Departments` WHERE uid = `$uid`");
while($row = mysql_fetch_assoc($result1))
{
$depts = array("Name" => $row['Name'], "Value" => $row['Value'], "ID" => $row['CollegeID']);
}

$result = mysql_query("SELECT * FROM `users` WHERE wmuid = '$uid'");
while($row = mysql_fetch_assoc($result)){

//POPULATE FORM FIELDS FROM DB

最佳答案

您的 $uid 周围有反引号。我不确定这到底会做什么,因为我怀疑你有一个与 $uid 中的名称相同的列,但它可能会导致一些奇怪的未定义行为。将 ` 更改为 ' 就像:

SELECT * FROM `Departments` WHERE `uid` = '$uid'

编辑

或者,如果uid列存储数字类型,则完全删除引号,例如:

SELECT * FROM `Departments` WHERE `uid` = $uid

关于php - MySQL 查询返回数千个空结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6867597/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com