-5

ページ数を確認した後、SELECTステートメントで30 RECORDSのLIMITキーワードを使用して結果をページ分割しようとしています。ヘッダーにはFORループ、結果行にはWHILEループの2つのループを使用し、LIMITを使用して制限します。 LIMITキーワードの後に​​変数を使用できます。私のコードは以下の通りです:

<?php 
    include 'dbconnect.php'; 

    ?>

    //--CHECKING number of records from STOCK table------------------------------------
    $di=mysql_query("SELECT * FROM CYLSTOCK_draft WHERE (DC_Date BETWEEN '$startdat' AND '$enddat' AND Ac_code='$custno' AND Product_Desc='$gas') OR (Ecr_dt BETWEEN '$startdat' AND '$enddat' AND Ac_code='$custno' AND Product_Desc='$gas') ORDER BY DC_Date");

    $numrows=mysql_num_rows($di);

    // number of rows to show per page
    $rowsperpage = 30;
    // find out total pages
    $totalpages = ceil($numrows / $rowsperpage);

    if ($numrows>0)
    {
        $sn=0;
        //--------for loop for Paging-------------
        for ($x=0; $x < $totalpages; $x++)
        {
            echo "<br><table width='622' border='1' cellspacing='0' cellpadding='5' align='center'>";
            echo "<tr>";
            echo "<td width='30' align='center' class='toprow'>SNo.</td>";
            echo "<td width='86' align='center' class='toprow'>DC Date</td>";
            echo "<td width='94' align='center' class='toprow'>DC No.</td>";
            echo "<td width='160' align='center' class='toprow'>Product Description</td>";
            echo "<td width='89' align='center' class='toprow'>Cylinder No.</td>";
            echo "<td width='91' align='center' class='toprow'>ECR Date</td>";
            echo "<td width='72' align='center' class='toprow'>ECR No.</td>";
            echo "</tr>";

            //---while loop with select statement limit to 30 records---------------------------------
            $dis=mysql_query("SELECT * FROM CYLSTOCK_draft WHERE (DC_Date BETWEEN '$startdat' AND '$enddat' AND Ac_code='$custno' AND Product_Desc='$gas') OR (Ecr_dt BETWEEN '$startdat' AND '$enddat' AND Ac_code='$custno' AND Product_Desc='$gas') ORDER BY DC_Date LIMIT '$sn', 30");
            while ($di2=mysql_fetch_assoc($dis))
            {
                $sn++;
                $k3=$di2['DC_Date'];
                $date_array = explode( "-", $k3 );
                $kk3 = sprintf( '%02d-%02d-%4d', $date_array[2], $date_array[1], $date_array[0]);
                $kk3a=strtotime($kk3);

                $k2=$di2['DC_No'];
                $k6=$di2['Product_Desc'];
                $k7=$di2['Cylinder_No'];
                $k5=$di2['Ecr_dt'];
                $kk5=strtotime($k5);
                $k4=$di2['Ecr_No'];

                echo "<tr>";
                echo "<td width='30' align='center' class='sty1'>$sn</td>";
                echo "<td width='86' align='center' class='sty1'>";
                if ($kk3a>0)
                {
                    echo $kk3;
                }
                echo "</td>";

                echo "<td width='94' align='center' class='sty1'>$k2</td>";
                echo "<td width='160' align='center' class='sty1'>$k6</td>";
                echo "<td width='89' align='center' class='sty1'>$k7</td>";
                echo "<td width='91' align='center' class='sty1'>";
                if($kk5>0)
                {
                    $date_array = explode( "-", $k5 );
                    $kk5 = sprintf( '%02d-%02d-%4d', $date_array[2], $date_array[1], $date_array[0]);
                    echo $kk5;
                }
                echo "</td>";

                echo "<td width='72' align='center' class='sty1'>";
                if (substr($k4,5) > 0)
                {
                    echo $k4;
                }
                echo "</td>";
                echo "</tr>";
            }
        //---End of for loop
        }
    }
    echo "</table><br>";
4

1 に答える 1

2
.. LIMIT '$sn', 30");  ..

$snの周りに引用符はありません

于 2012-08-15T10:51:03.583 に答える