Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP中的分页每页仅更新1行_Php_Mysql_Pagination - Fatal编程技术网

PHP中的分页每页仅更新1行

PHP中的分页每页仅更新1行,php,mysql,pagination,Php,Mysql,Pagination,需要帮助修复我的分页。我限制每页显示5行,每次我转到下一页时,它只更新底部的1行,而不是每页显示5个新项目 这是我目前拥有的。抱歉发了这么长的代码。目前,我所做的解决方法是将$listcount设置为1000,以显示所有要同时禁用分页的项 <?php $global_connection = db_connect(); $tabledata = ""; $totalpages = 0; $curpageoffset = 0; $listco

需要帮助修复我的分页。我限制每页显示5行,每次我转到下一页时,它只更新底部的1行,而不是每页显示5个新项目

这是我目前拥有的。抱歉发了这么长的代码。目前,我所做的解决方法是将$listcount设置为1000,以显示所有要同时禁用分页的项

    <?php
    $global_connection = db_connect();
    $tabledata = "";

    $totalpages = 0;
    $curpageoffset = 0;
    $listcount = 5;
    $pageparam = "";

    $colspan = 7;
    $isownpost = 0;


    if ($global_connection) {
        $ctr = 0;
        $orderbyclause = "order by buyinfo_created";
        $limitstr = "";
        $addtable = "";
        $clause = "and buyinfo.buyinfo_deadline>='".date('Y-m-d H:i:s')."' and buyinfo.buyinfo_status<3";
        if (isset($_REQUEST['recommend'])) {
            $pageparam .= "&recommend=".$_REQUEST['recommend'];
            $sectiontitle = "Recommended posts";
            $addtable = ",recommend";
            $clause .= " and recommend.buyinfo_id=buyinfo.buyinfo_id and recommend.user_id=".util_getuserid();
        } else if (isset($_REQUEST['member'])) {
            $pageparam .= "&member=".$_REQUEST['member'];
            $orderbyclause .= " desc";
            if ($_REQUEST['member'] == util_getuserid() || $_REQUEST['member'] == 0) {
                $isownpost = 1;
                $colspan--;
                $sectiontitle = "My Posts";
                // Do not hide completed/expired items
                $clause = " and user.user_id='".util_getuserid()."'";
            } else {
                $sectiontitle = "Posts by ".db_getvalue("select user_login from user where user_id='".$_REQUEST['member']."'", $global_connection);
                $clause .= " and user.user_id='".$_REQUEST['member']."'";
            }
        } else {
            $sectiontitle = "Ongoing Posts";
        }
        $totalrows = db_getvalue("select count(buyinfo_id) from buyinfo,user $addtable where buyinfo.user_id=user.user_id $clause $orderbyclause", $global_connection);
        if ($totalrows == "")
            $totalrows = 0;
        $totalpages = ceil($totalrows/$listcount);
        if ($totalpages > '1') {
            $curpageoffset = 0;
            if (isset($_REQUEST['offset'])) {
                if ($_REQUEST['offset'] >= $totalpages)
                    $curpageoffset = $totalpages - 1;
                else if ($_REQUEST['offset']>0)
                    $curpageoffset = $_REQUEST['offset'];
            }
            $limitstr = " limit $curpageoffset,$listcount";
        }

        $classname = "postlist-oddrow";
        $buyresults = db_query("select * from buyinfo,user $addtable where buyinfo.user_id=user.user_id $clause $orderbyclause $limitstr", $global_connection);
        while ($buyrow = db_getnextdata($buyresults)) {
            $ctr++;
            $totalbids = db_getvalue("select count(buyinfoquote_id) from buyinfoquote where buyinfo_id='".$buyrow['buyinfo_id']."'", $global_connection);
            $tabledata.= "<tr class='$classname'>";
//          $tabledata.= "<td align=right>".util_numfmt($ctr)."</td>";
            $tabledata.= "<td><a href='/posts/?item=".$buyrow['buyinfo_id']."' target='_blank'><h4>".util_displaystatictext($buyrow['buyinfo_title'])."</h4></a></td>";
            $tabledata.= "<td>";
            $exampledata = "<table  class='posts-imagerholder'><tr>";
            $imgctr = 0;
            $imgresults = db_query("select buyinfoexample_imgurl from buyinfoexample where buyinfo_id=".$buyrow['buyinfo_id'], $global_connection);
            while ($imgrows = db_getnextdata($imgresults)) {
                $imgctr++;
                $exampledata.= "<td align=center valign=top><img  alt='loading...' style='border: none;' class='posts-image' src='" . $imgrows['buyinfoexample_imgurl'] . "' /></td>";
            }
            if ($imgctr == 0)
                $exampledata = "No examples";
            else
                $exampledata.= "</tr></table>";

            $tabledata.= "$exampledata</td>";
            if ($buyrow['user_id'] === '2') {
                    $tabledata.= "<td><a href='/posts/?item=".$buyrow['buyinfo_id']."' target='_blank'>".util_displaystatictext($buyrow['buyinfo_name'])."</a></td>";
            } else {
                    $tabledata.= "<td><a href='' OnClick='util_reload(\"profile/?member=".$buyrow['user_id']."\"); return false;'>".util_displaystatictext($buyrow['buyinfo_name'])."</a></td>";
            }
            $tabledata.= "<td>".$buyrow['buyinfo_budget']."</td>";
            $tabledata.= "<td>".$buyrow['buyinfo_notes']."</td>";
            $tabledata.= "<td>".util_datetimefmt($buyrow['buyinfo_created'])."</td>";
            $tabledata.= "</tr>";

            if ($classname == "postlist-oddrow")
                $classname = "postlist-evenrow";
            else
                $classname = "postlist-oddrow";
        }
        if ($ctr == 0) {
            if (isset($_REQUEST['recommend']))
                $tabledata = "<tr><td colspan='$colspan' align='center'>We have no recommendations. Please try updating your keywords in your profile.</td></tr>";
            else
                $tabledata = "<tr><td colspan='$colspan' align='center'>No posts</td></tr>";
        }
        db_disconnect($global_connection);
    } else {
        $tabledata = "<tr><td colspan='$colspan' align='center'>Server Error</td></tr>";
    }
?>
<div style='background-color: #f4f4f4; padding: 60px 0px;'>

<table width=90%>
<tr><td>
<h4><?php 

$src=$_SESSION['PROFILE_PICTURE'];
echo "<img src='".$src."' width='50px'>  ".$_SESSION['FULLNAME']."<br/><br/>" ;
echo  "<img src='$global_baseurl"."img/postsicon.png'> $sectiontitle"; 
?></h4>
<table border=0 cellspacing=0 cellpadding=5 class='postlist'>
<?php
    $postcolnames = "<tr class='postlist-colname'>";

    $postcolnames .= "<td>Title</td>";
    $postcolnames .= "<td align=center >Examples</td>";
    if ($isownpost == 0) {
        $postcolnames .= "<td>Buyer</td>";

    }
    $postcolnames .= "<td>Budget</td>";
    $postcolnames .= "<td>Notes</td>";
    $postcolnames .= "<td>Date Posted</td>";
    $postcolnames .= "</tr>";

    echo $postcolnames;
    echo $tabledata;
    echo str_replace("postlist-colname", "postlist-colname postlist-evenrow", $postcolnames);
?>
</table>
</td></tr>
<?php
    if ($totalpages>1) {
            echo "<tr><td><ul class='pagination'>";
            echo "<li><a href='' aria-label='Previous' ";
            if ($curpageoffset == 0) {
                echo "onclick='return false;'";
            } else {
                echo "onclick='util_reload(\"posts/?offset=".($curpageoffset-1)."$pageparam\"); return false;'";
            }
            echo " ><span aria-hidden='true'>&laquo;</span></a></li>";

            $tmpctr = 0;
            while ($tmpctr < $totalpages) {
                $curstyle = "";
                if ($tmpctr == $curpageoffset)
                    $curstyle = "class='active'";

                echo "<li $curstyle><a href='' onclick='util_reload(\"posts/?offset=$tmpctr$pageparam\"); return false;'>";
                $tmpctr++;
                echo "$tmpctr</a></li>";
            }

            echo "<li><a href='' aria-label='Next' ";
            if ($curpageoffset >= $totalpages-1) {
                echo "onclick='return false;'";
            } else {
                echo "onclick='util_reload(\"posts/?offset=".($curpageoffset+1)."$pageparam\"); return false;'";
            }
            echo " ><span aria-hidden='true'>&raquo;</span></a></li>";

            echo "</ul></td></tr>";
    }
?>
</table>
</div>

应该是

$curpageoffset = $_REQUEST['offset']*$listcount-1;
当前,如果将起始位置增加到on,则应将其增加页码乘以限制(减1)

currentoffset、listcount、currentpage、totalpages、requestoffset

$currentPage = ceil($requestOffset/$listcount);
if ($currentPage > $totalpages) {$currentpage = 0;}
$currentoffset = $currentPage * $listcount;
然后


这是很多你希望我们阅读的代码我知道@Dagon只是不知道该怎么办如果用户点击2(第2页),页面会更新,并突出显示5(第5页),而不是2。但在URL上显示offset=1这几乎奏效了。谢谢但是,第1页的最后一项显示为第2页的第一项。对不起,我不明白您的意思。你能进一步解释一下吗?谢谢大家!@Xiaosong偏移量应为(当前页码-1)*每页限制$_请求['offset']-1*$listcount;是这样但不起作用吗你是说$_Request['offset']是当前页码吗?如果这样做,sql应该是这样的:limit($\u REQUEST['offset']-1)*$listcount,$listcount不起作用。一直让我回到第一页
$totalpages = ceil($totalrows/$listcount);
    if ($totalpages > '1') {
        $curpageoffset = 0;
        if (isset($_REQUEST['offset'])) {
            if ($_REQUEST['offset'] >= $totalpages)
                $curpageoffset = $totalpages - 1;
            else if ($_REQUEST['offset']>0)
                $curpageoffset = $_REQUEST['offset'];
        }
        $limitstr = " limit $curpageoffset,$listcount";
    }
$currentPage = ceil($requestOffset/$listcount);
if ($currentPage > $totalpages) {$currentpage = 0;}
$currentoffset = $currentPage * $listcount;
$limitstr = " limit $curpageoffset,$listcount";