2012-08-15 3 views
-5

페이지 수를 확인한 후, SELECT 문에서 30 RECORDS에 대한 LIMIT 키워드를 사용하여 결과를 페이지 매김하려고합니다. 2 개의 루프를 사용하고, FOR 루프는 헤더에, WHILE 루프는 결과 행을, LIMIT를 사용하여 제한하기, LIMIT 키워드 뒤에 변수를 사용할 수 있는지 알고 싶습니다. 내 코드는 다음과 같습니다 : $의 SN 주위mysql 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>"; 
+1

당신이 LIMIT''에'$의 sn' var에 넣어하지 않고 그 순간이 var에 '0'과 동일합니다. – Serjio

+0

PHP 코드를 열면 닫을 수 있습니다. 코드를 포맷 할 때 발견되었습니다. – Fluffeh

+0

코드 조각 만 따라서 닫힙니다.>>가 없습니다! 감사합니다 – user1114409

답변

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

따옴표가

+0

정말 고맙습니다. – user1114409