【问题标题】:PHP Mysql_fetch_assoc is Omitting last rowPHP Mysql_fetch_assoc 正在省略最后一行
【发布时间】:2013-01-03 10:05:18
【问题描述】:

在 PHP 中,MYSQL_FETCH_ASSOC 省略了 Last Row。这从未发生过。但这一次它让我在最后一刻陷入了困境。

即使我已经提出了 mysql_num_rows 结果是 14 条记录 - 但在列表中它只显示 13 条记录并且第 14 条记录被省略了。

感谢任何形式的帮助。

                $uno = $_GET["uno"];

                $xtc1 = 'select * from rform where uno="' . $uno . '" order by rno DESC';
                $xtc = mysql_query($xtc1) or die('User Reservation Retrival Error : ' . mysql_error());

                $trno = mysql_fetch_assoc($xtc);
                $trow = mysql_num_rows($xtc);


                echo '<p>List of Onlilne Reservations made by <strong style="font-weight:bold; color:red;">' . ucwords($trno["cname"]) . ' (' . $trow . ')</strong></p>';

                echo '<table cellpadding="5" cellspacing="0" border="1">';
                    echo '<tr>';
                        echo '<td colspan="5" style=" font-size:14px; text-align:center; font-weight:bold; color:red;">' . ucwords($trno["cname"]) . '</td>';
                    echo '</tr>';
                    echo '<tr>';
                            echo '<th>R.NO</th>';
                            echo '<th>From</th>';
                            echo '<th>To</th>';
                            echo '<th>Date &amp; Time of<Br>Travel</th>';
                            echo '<th>Reserved On</th>';
                        echo '</tr>';   
                    while($mtn = mysql_fetch_assoc($xtc)){
                        $dt = $mtn["csdate"] . ' ' . $mtn["ctime"];
                        echo '<tr>';
                            echo '<td>' . $mtn["rno"] . '</td>';
                            echo '<td>' . $dt . '</td>';
                            echo '<td>' . $mtn["caddr"] . '</td>';
                            echo '<td>' . $mtn["cdest"] . '</td>';
                            echo '<td>' . date('d-M-Y',strtotime($mtn["tstamp"])) . '</td>';
                        echo '</tr>';   
                    }
                    echo '</table>';

【问题讨论】:

    标签: php


    【解决方案1】:

    你有一个额外的$trno = mysql_fetch_assoc($xtc) 似乎要丢弃。这是您缺少的行。只需删除该行。

    【讨论】:

    • 就是这样,谢谢 Kolink
    【解决方案2】:

    删除第一个$trno = mysql_fetch_assoc($xtc); 即可解决此问题。

    如果您需要在循环之前阅读$xtc 的第一行。可以将while循环改成do-while,不用删除第一个$mtn = mysql_fetch_assoc($xtc);

    do{
        //whatever
    }while($mtn = mysql_fetch_assoc($xtc));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-18
      • 2012-08-09
      • 2013-10-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多