0
function supervisor_from_email($email, $p_id) {
    $email = sanitize($email);
    return mysql_query("SELECT pm.supervisor FROM project_members AS pm JOIN users AS u ON pm.project_member_id = u.user_id WHERE u.email = $email AND pm.project_id = $p_id");
}

是我调用的函数,$email 和 $p_id 是正确的,我已经在数据库上运行了查询,它返回了正确的值(1 或 0)

我希望能够在页面上回显它,然后根据它决定是否检查复选框,但是当我在运行函数后尝试回显时,如下所示:

$supervisor = supervisor_from_email($email, $p_id);
echo $supervisor;

这没用?有任何想法吗?

4

3 回答 3

2

尝试

$result = mysql_query("SELECT pm.supervisor FROM project_members AS pm JOIN users AS u ON pm.project_member_id = u.user_id WHERE u.email = '$email' AND pm.project_id = $p_id");
if (!$result) 
{
die(mysql_error()); 
}

while($row = mysql_fetch_array($result))
{
echo $row['supervisor'];
}

或者

$result = mysql_query("SELECT pm.supervisor FROM project_members AS pm JOIN users AS u ON pm.project_member_id = u.user_id WHERE u.email = '$email' AND pm.project_id = $p_id");
if (!$result) 
{
die(mysql_error()); 
}
mysql_result($result,0);
于 2013-04-17T18:41:18.747 回答
1

mysql_query返回一个资源,因此您必须获取此资源以通过使用获取绑定到此资源的数据mysql_fetch_array,然后您必须转到新mysqli库,因为旧mysql库很快就会被弃用:)

尝试这个 :

function supervisor_from_email($email, $p_id)
    {
        $email = sanitize($email);
        $email_rs = mysql_query("SELECT pm.supervisor FROM project_members AS pm JOIN users AS u ON pm.project_member_id = u.user_id WHERE u.email = '$email' AND pm.project_id = $p_id");
        if(is_resource($email_rs))
            {
                $email_res = mysql_fetch_array($email_rs);
                $email = $email_res[0];
                return $email;
            }
        else
            return "Invalid supervisor";
    }

告诉我结果:)

于 2013-04-17T18:41:45.980 回答
1

你的功能应该是这样的..

function supervisor_from_email($email, $p_id) {
    $email = sanitize($email);
    $result=mysql_query("SELECT pm.supervisor FROM project_members AS pm JOIN users AS u ON pm.project_member_id = u.user_id WHERE u.email = $email AND pm.project_id = $p_id");
   $row=mysql_fetch_assoc($result);
    return $row['supervisor'];

}

它将返回带有值的数组试试这个

于 2013-04-17T18:43:04.683 回答