dsgd5756 2014-05-28 08:42
浏览 27
已采纳

mysql_num_rows没有工作的那种

I got this

for($i = 1; $i < 301; $i++)
{
    $r8 = mysql_query("SELECT * FROM full_dump WHERE id_fd='".$last_id."' AND field_".$i." LIKE '%JAL?%' order by field_".$i." desc limit 0,1")or die(mysql_error());
    if ( mysql_num_rows($r8) == 1){
        while($row = mysql_fetch_array($r8))
        {
            $i4 = $i+1;
            $jalfd = trim($row['field_'.$i4.'']);
        }
    }
    else {
        $jalfd = "N/A";
    }
}

It is part of a pile_upload script. All works but not this. When I upload a file it may or may not contain the word JAL? and the next line has its value. No matter what, the end value of jalfd is N/A. When I do

echo mysql_num_rows($r8);

I get the following when I have JAL? in the text file (you'll see a 1 in there)

000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

an when I don't have JAL? (there is no 1)

000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

I even tried

if ( intval(mysql_num_rows($r8)) == 1){

with no luck.

  • 写回答

1条回答 默认 最新

  • doumizhi0809 2014-05-28 08:54
    关注

    No matter what, the end value of jalfd is N/A

    With your Logic, the value of $jalfd after the end of the loop only depends upon your 300th loop iteration. On every iteration you are overwriting it. If your 300th iteration resulted in rows not being 1 you will get $jalfd="N/A" regardless of what the previous values were.

    A simple fix using your design itself, will be to initialize the value

    $jalfd = "N/A";
    

    before your loop starts, and remove the else section completely. It wont be needed then.

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

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)