mysql_fetch_assoc():提供的资源不是有效的MySQL结果资源

时间:2017-12-01 15:41:31

标签: php

我不知道如何解决我的问题。

这是我的错误行代码:

$query = mysql_query("SELECT client FROM `timecards` GROUP BY `client`");
while($row=mysql_fetch_assoc($connection,$query)) {
    $cc .= '<option value="'.$row['client'].'">'.$row['client'].'</option>';
}

和我的零件代码:

if($_GET) {
    $start = date('Y-m-d H:i:s', strtotime($_GET['s']));
    $end = date('Y-m-d H:i:s', strtotime($_GET['e']));
    $client = preg_replace('/[^a-zA-Z0-9 ]+/', '', $_GET['client']);
    $query = mysql_query("SELECT * FROM `timecards` WHERE `client`='$client' && `punch` BETWEEN '$start' AND '$end' ORDER BY `punch`");
    while($row = mysql_fetch_assoc($query)) {
        $q = question(base64_decode($row['comment']));
        if($t === null) {
            $t = $row['punch'];
            $results .= "<br />" . format($row['punch']) . $q;
        } else {
            $j = timediff($t, $row['punch']);
            $results .= "to " . format($row['punch']) . $q . " = " . His($j);
            $total += $j;
            $t = null;
        }
    }
    if($t !== null) {
        $results .= " STILL CLOCKED IN";
    }
    $results .= "<br /><br /><strong>Total:</strong> " . His($total);
}

$query = mysql_query("SELECT client FROM `timecards` GROUP BY `client`");
while($row = mysql_fetch_assoc($connection, $query)) {
    $cc .= '<option value="' . $row['client'] . '">' . $row['client'] . '</option>';
}

1 个答案:

答案 0 :(得分:0)

mysql_fetch_assoc()接受一个参数 - 查询句柄。您正在传递连接句柄和查询句柄。您应该将连接句柄传递给mysql_query()。

代码应为:

$query = mysql_query("SELECT client FROM `timecards` GROUP BY `client`", $connection);

while($row=mysql_fetch_assoc($query)) {
...
相关问题