如何在php中删除警告“mysql_num_rows()期望参数1为资源”

时间:2014-02-04 11:46:54

标签: php mysql mysqli

我创建了一个php页面,其中我想从数据库中获取数据但是当我运行它时会给出警告“mysql_num_rows()期望参数1是资源”。

我如何删除此警告?

这是我的代码:

$strQuery1 = "select DATE_FORMAT(transactions.transaction_date,'%m-%d-%Y') as transaction_date,sum(amount)as Amount from transactions where event_id='7' group by  DATE_FORMAT(transactions.transaction_date,'%m-%d-%Y')";
$result1 = $GLOBALS ['mysqli']->query ($strQuery1) or die ($GLOBALS ['mysqli']->error . __LINE__);
$rows=mysql_num_rows($result1);
while($rs1=$result1->fetch_assoc()){    
    $res1[]=$rs1;                   
}
for ($i = 0 ; $i <=30 ; $i++) {
    foreach($res1 as $r){
        if($r['transaction_date']==$dates[$i]){
            $substrXML1= "<set value='" . $r['Amount'] ."' />";
            break;
        } else
           {
            $substrXML1= "<set value='0' />";
        }
    }
        $strXML1 .=$substrXML1;
}
    $strXML1.="</dataset>";

2 个答案:

答案 0 :(得分:0)

$rows=mysqli_num_rows($result1);

答案 1 :(得分:-2)

这可能对你有用

$rows = mysql_num_rows($result1); //old
$rows = mysql_query($result1); //changed
while($rs1=mysql_fetch_array($rows))
or
while($rs1=$result1->fetch_assoc()){    
    $res1[]=$rs1;                   
}