dps123456789 2014-03-11 22:55
浏览 43
已采纳

mysql_fetch_row和mysql_fetch_array之间的冲突

I have a function in PHP that give me some values from DB

$select = mysql_query("SELECT * FROM sfide WHERE accepted = 0");

if($select){
    if(mysql_fetch_row($select) != 0){
        $sep = "~";
        $return = "";
        $i = 0;
        while($row = mysql_fetch_array($select)){
            if($i > 0){
                $return = $return.",";
            };
            $return = $return.$row['id'].$sep.$row['from_'];
            $i += 1;
        }
        return $return;
    }else{
        return "NO";
    }
}else{
return "E, 000, SELECT, ".mysql_error();        
}

The problem is that if I do like in the code above it returns me nothing, instead, if I duplicate the select variable it works:

$select = mysql_query("SELECT * FROM sfide WHERE accepted = 0");
$num_select = mysql_query("SELECT * FROM sfide WHERE accepted = 0");
if($select){
    if(mysql_fetch_row($num_select) != 0){
        $sep = "~";
        $return = "";
        $i = 0;
        while($row = mysql_fetch_array($select)){
            if($i > 0){
                $return = $return.",";
            };
            $return = $return.$row['id'].$sep.$row['from_'];
            $i += 1;
        }
        return $return;
    }else{
        return "NO";
    }
}else{
return "E, 000, SELECT, ".mysql_error();        
}

Why ?

  • 写回答

1条回答 默认 最新

  • dougua9328 2014-03-11 23:01
    关注

    Instead of

    mysql_fetch_row($select) != 0

    use

    mysql_num_rows($select) != 0

    that will return an int for you to compare.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动