MySQL查询返回数千个空结果

时间:2011-07-29 01:09:33

标签: php mysql

当我运行第二个查询来选择部门时,它会返回我的部门列表,就像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

1 个答案:

答案 0 :(得分:2)

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

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

修改

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

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