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 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数