簡體   English   中英

PHP我的SQL分頁幫助需要鏈接和推進下一個偏移量

[英]php my sql pagination help need for links and advancing the next offset

嗨,我正在嘗試對一個php mysql數據庫進行分頁,但我無法弄清楚是什么使結果移至下一頁,它停留在記錄行零,我將如何更改以使其轉到下一組結果? 這是掛鈎到導航鏈接的偏移量,它是否必須重新調用mysql查詢? 這是如何運作的?

    //pagination
    //find out how many rows are in the table 

    $sql = "SELECT * FROM hotels_database";
    $result = mysql_query($sql, $con) or trigger_error("SQL", E_USER_ERROR);
    $r = mysql_fetch_row($result);
    $numrows = $r[0];


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

    // get the current page or set a default
    if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
    // cast var as int
    $currentpage = preg_replace('#[^0-9]#i','', $_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 hotels_database LIMIT $offset, $rowsperpage";
    $result = mysql_query($sql, $con) or trigger_error("SQL", E_USER_ERROR);

    // while there are rows to be fetched...
    while ($list = mysql_fetch_assoc($result)) {
    // echo data


    for ($stars=1;$stars<=floor($list['stars']);$stars++){
    $star_string .= "<img src='images/star.jpg'/>";

    }

    if (($list['stars']-floor($list['stars']))> 0){
    $star_string .= "<img src='images/half_star.jpg'/>";
    }

    $hotels_database .= "<div style='display:table-row;height:70px;'><div style='width:60px;height:60px;display:table-cell;float:left;'><img src='".$list['pic']."' width='60px'/></div>"."<div style='width:280px;display:table-cell;vertical-align:top;text-align:left;padding-left:5px;font-size:12px;'><a href='#' class='database_link'>".$list['hotel']."</a>".$star_string."<br/><span style='font-size:10px;'>".$list['addy']."</span><br/>Guest score: <span style='color:red;font-size:14px;'>".$list['score']."</span> out of 10"."<br/>"."<li class='database_arrow'>Display Amenities & More Info</li>"."</div>"."<div style='width:78px;height:60px;display:table-cell;vertical-align:top;'><span style='font-family:arial;color:green;font-size:15px;'>$".$list['price']."</span><br/>per night<div style='border-radius:10px;background-color:#1284d3;height:25px;width:70px;left:10px;top:10px;position:relative;border:1px black solid;color:white;font-family:arial;line-height:8px;'><br/>select</div><br/></div>"."</div><hr style='color:#c8ff78;'/>";

    $star_string="";
    } // end while

    /******  build the pagination links ******/
    // range of num links to show



    //pagination
    /*     

是的,所以我不知道如何轉到下一個偏移量,在這種情況下我要使用什么href? 為什么在我的爸爸欄中沒有顯示當前頁面查詢字符串? 請看一下,

正如DN所說,代碼會有所幫助,但總的來說

if(isset($_GET['offset']) {

$offset = $_get['offset'];

}

else{

$offset = 0;

}

然后在SQL調用中添加:

'what ever the call is' "limit $limit offset $offset"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM