2012-02-09 23 views
3

私の問題改ページを追加したい:ここ=は、私は私のスクリプトで

<?php 

//while there are rows to be fetched... 
while ($row = mysql_fetch_assoc($result)) 
{ 
    ?> 
    <td><?php echo $row['id']?></td> 
    <td><?php echo $row['user_id']?></td>          
    <td><?php echo $row['imei']?></td> 
    <td><?php echo $row['time_stamp']?></td> 
    <td><?php echo $row['sending_time']?></td> 
    <td><?php echo $row['RSSI']?></td> 
    <td><?php echo $row['BSSID']?></td> 
    <td><?php echo $row['SSID']?></td> 
    <td><?php echo $row['sleep_time_start']?></td> 
    <td><?php echo $row['sleep_time_end']?></td> 
    </tr>   
    <?php 
} //// end while 
?> 

を:enter image description here

これは私wifi_log.phpファイルである---をここに表示

<?php // find out how many rows are in the table 
$sql = "SELECT COUNT(*) FROM log_wifi"; 
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); 
$r = mysql_fetch_row($result); 
$numrows = $r[0]; 

// number of rows to show per page 
$rowsperpage = 10; 
// find out total pages 
$totalpages = ceil($numrows/$rowsperpage); 
echo $resultpage= $_GET['results_page']; 
// get the current page or set a default 
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { 
    // cast var as int 
    $currentpage = (int) $_GET['currentpage']; 
} else { 
    // default page num 
    $currentpage = 1; 
} // end if 


// if current page is greater than total pages... 
if ($currentpage > $totalpages) { 
    // set current page to last page 
    $currentpage = $totalpages; 
} // end if 

// if current page is less than first page... 
if ($currentpage < 1) { 
    // set current page to first page 
    $currentpage = 1; 
} // end if 

// the offset of the list, based on current page 
$offset = ($currentpage - 1) * $rowsperpage; 

// get the info from the db 
$sql = "SELECT * FROM log_wifi LIMIT $offset, $rowsperpage"; 
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); 
?> 

マイデータ< < 1 2 3 >> LAST - >これが正常に動作しています

<tr><th id="footer" colspan="10"> 

    <?php 
    /****** build the pagination links ******/ 
// range of num links to show 
$range = 3; 
if($currentpage==1) 
{ 
    echo '<span class="prn"> First &lt;&lt;</span>&nbsp;'; 
} 
if ($currentpage > 1) { 
    // show << link to go back to page 1 
    echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1&result_page=$resultpage'>First</a> "; 
    // get previous page num 
    $prevpage = $currentpage - 1; 
    // show < link to go back to 1 page 
    echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage&result_page=$resultpage'><</a> "; 
} // end if 

// loop to show links to range of pages around current page 
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { 
    // if it's a valid page number... 
    if (($x > 0) && ($x <= $totalpages)) { 
     // if we're on current page... 
     if ($x == $currentpage) { 
     // 'highlight' it but don't make a link 
     echo " <b>$x</b> "; 
     // if not current page... 
     } else { 
     // make it a link 
     echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x&result_page=$resultpage'>$x</a> "; 
     } // end else 
    } // end if 
} // end for 

// if not on last page, show forward and last page links   
if ($currentpage != $totalpages) { 
    // get next page 
    $nextpage = $currentpage + 1; 
    // echo forward link for next page 
    echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage&result_page=$resultpage'>></a> "; 
    // echo forward link for lastpage 
    echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages&result_page=$resultpage'>Last</a> "; 
} // end if 
else 
{ 
    echo '<span class="prn"> Last &gt;&gt;</span>&nbsp;'; 
} 
/****** end build pagination links ******/ 

?> 

問題は、私はあなたがすでに仕事をしていませんが、変数を持って

<form action="./wifi_log.php" method="get"> 
    <select name="results_page" id="results_page" onchange="this.form.submit();" > 
     <option value="5" NO >5</option> 
     <option value="10" SELECTED >10</option> 
     <option value="20" NO>20</option> 
     <option value="50" NO >50</option> 
    </select>  
    results per page 
</form></th> 
    </tr> 
    </tbody> 
</table>    

答えて

1

を知っていることを行う方法をここにあります。あなたは送信している$ _POST変数からそれを入力するだけです。

// number of rows to show per page 
if(isset($_GET['results_page']) && is_numeric($_GET['results_page'])) 
{ 
    $rowsperpage = (int)$_GET['results_page']; 
} 
else 
{ 
    $rowsperpage = 10; 
} 
+0

SQLクエリで書くために何を?@ダンは – User1988

+0

あなたはそのようなページの残りの部分を残すことができます。 – Dan

+0

ああ、私はちょうどあなたがポストの代わりにゲットを使うことに気づいた。私のコードで投稿を$ _GETに置き換えるとうまくいくはずです。 – Dan

2

あなたのフォームメソッドはgetです。あなたはこれが私の最後のページネーションの符号化である

$rowsperpage = isset($_GET['results_page']) && is_numeric($_GET['results_page']) ? $_GET['results_page'] : 10; 
+0

ああ、その正常に動作します。 – User1988

0

$rowsperpage = 10; 

を置き換えることができ :

 // number of rows to show per page 
    //$rowsperpage = 10; //I COMMENTED THIS AND WRITEN FOLLOWING 
/***********************************************************/ 
    if(isset($_GET['results_page']) && is_numeric($_GET['results_page'])) 
    { 
     $rowsperpage = (int)$_GET['results_page']; 
    } 
    else 
    { 
     $rowsperpage = 10; 
    } 
/************************************************************/ 
    // find out total pages 
    $totalpages = ceil($numrows/$rowsperpage); 
    echo $resultpage= $_GET['results_page']; 
    // get the current page or set a default 
    if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { 
     // cast var as int 
     $currentpage = (int) $_GET['currentpage']; 
    } else { 
     // default page num 
     $currentpage = 1; 
    } // end if 


    // if current page is greater than total pages... 
    if ($currentpage > $totalpages) { 
     // set current page to last page 
     $currentpage = $totalpages; 
    } // end if 

    // if current page is less than first page... 
    if ($currentpage < 1) { 
     // set current page to first page 
     $currentpage = 1; 
    } // end if 

    // the offset of the list, based on current page 
    $offset = ($currentpage - 1) * $rowsperpage; 

    // get the info from the db 
    $sql = "SELECT * FROM log_wifi LIMIT $offset, $rowsperpage"; 
    $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); 

これが私の記録では、

//while there are rows to be fetched... 
while ($row = mysql_fetch_assoc($result)) 
{ 
    ?> 
    <td><?php echo $row['id']?></td> 
    <td><?php echo $row['user_id']?></td>          
    <td><?php echo $row['imei']?></td> 
    <td><?php echo $row['time_stamp']?></td> 
    <td><?php echo $row['sending_time']?></td> 
    <td><?php echo $row['RSSI']?></td> 
    <td><?php echo $row['BSSID']?></td> 
    <td><?php echo $row['SSID']?></td> 
    <td><?php echo $row['sleep_time_start']?></td> 
    <td><?php echo $row['sleep_time_end']?></td> 
    </tr>   
    <?php 
} //// end while 

を表示し、fianllyこれが私ですpリンク内やコンボボックスでagination

/****** build the pagination links ******/ 
// range of num links to show 
$range = 3; 
if($currentpage==1) 
{ 
    echo '<span class="prn"> First &lt;&lt;</span>&nbsp;'; 
} 
if ($currentpage > 1) { 
    // show << link to go back to page 1 
    echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1&results_page=$rowsperpage'>First</a> "; 
    // get previous page num 
    $prevpage = $currentpage - 1; 
    // show < link to go back to 1 page 
    echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage&results_page=$rowsperpage'><</a> "; 
} // end if 

// loop to show links to range of pages around current page 
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { 
    // if it's a valid page number... 
    if (($x > 0) && ($x <= $totalpages)) { 
     // if we're on current page... 
     if ($x == $currentpage) { 
     // 'highlight' it but don't make a link 
     echo " <b>$x</b> "; 
     // if not current page... 
     } else { 
     // make it a link 
     echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x&results_page=$rowsperpage'>$x</a> "; 
     } // end else 
    } // end if 
} // end for 

// if not on last page, show forward and last page links   
if ($currentpage != $totalpages) { 
    // get next page 
    $nextpage = $currentpage + 1; 
    // echo forward link for next page 
    echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage&results_page=$rowsperpage'>></a> "; 
    // echo forward link for lastpage 
    echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages&results_page=$rowsperpage'>Last</a> "; 
} // end if 
else 
{ 
    echo '<span class="prn"> Last &gt;&gt;</span>&nbsp;'; 
} 
/****** end build pagination links ******/ 

?> 

<form action="./wifi_log.php" method="get"> 
    <select name="results_page" id="results_page" onchange="this.form.submit();" > 
     <option value="5" NO >5</option> 
     <option value="10" SELECTED >10</option> 
     <option value="20" NO>20</option> 
     <option value="50" NO >50</option> 
    </select>  
    results per page 
</form> 

ハッピー:)

関連する問題