我从数据库中获得了20个数组数据,因此决定将其放入表格中以在页面上显示。

<tbody>
        <?php for ($n=0; $n < 10; $n++) { ?>
            <tr>
            <td><?php echo $n+1;
                $prescription_array=explode('/',$new_array2[$n]);
            ?>
            </td>
            <td><?php

            for ($i=0; $i < 10; $i++) {
                echo "<font size='5'>".$prescription_array[$i]."</font>";
                $x++;
            }
            ?>
            </td>
        </tr>
    <?php }?>
</tbody>


如果我尝试打印所有重叠在页眉和页脚上的数据时尝试显示所有数据,则使用for循环来限制正在显示的数据。所以我的问题是如何将剩余数据显示到下一页。我找不到更好的解决方案。

$sql = "SELECT prescriptions FROM tblprescriptions WHERE `ID`='$ID' AND `appID`='$appID' ";
            $query = $this->dbh->prepare($sql);
            $query->execute();

if($row = $query->fetch(PDO::FETCH_ASSOC)){
    $prescriptions = $row['prescriptions'];
}

return @$prescriptions;


这是我用来从数据库获取数据的查询。
php - 如何将表行分为2并显示为页面-LMLPHP
这是我想要实现的,但是我只能得到第一页,而且我不知道如何显示剩余的数组。我正在使用chrome;关于如何显示剩余数据的任何想法?

amen (amen) 50mg -- 20pcs. -- 5x per day -- morning noon and evening -- 5 days1/, yes (yes) 50mg -|- #50 -|- 5x per day -|- morning noon and evening -|- 10 days/, 51 (51) 51mg | #51 | 5x per week | morning noon and evening | 10 days/, bio (gesic) || 50mg || #50 || 5x per week || morning noon and evening || 10 days/, biogesic (paracetamol) | | 250mg | | #20 | | 5x per week | | morning noon and evening | | 14 days/, mefenamic (paracetamol)_100mg_#10_3x per week_morning noon and evening_10 days/, biogesic (paracetamol) = 250mg = #20 = 5x per week = morning noon and evening = 14 days/, bio (tamol) :: 50mg :: #50 :: 5x per week :: morning noon and evening :: 14 days/, bio (tamol) \ 50mg \ #50 \ 5x per week \ morning noon and evening \ 14 days/, bio (tamol) + 50mg + #50 + 5x per week + morning noon and evening + 14 days/, amen (amen) 50mg -- 20pcs. -- 5x per day -- morning noon and evening -- 5 days1/, yes (yes) 50mg -|- #50 -|- 5x per day -|- morning noon and evening -|- 10 days/, 51 (51) 51mg | #51 | 5x per week | morning noon and evening | 10 days/, bio (gesic) || 50mg || #50 || 5x per week || morning noon and evening || 10 days/, biogesic (paracetamol) | | 250mg | | #20 | | 5x per week | | morning noon and evening | | 14 days/, mefenamic (paracetamol)_100mg_#10_3x per week_morning noon and evening_10 days/, biogesic (paracetamol) = 250mg = #20 = 5x per week = morning noon and evening = 14 days/, bio (tamol) :: 50mg :: #50 :: 5x per week :: morning noon and evening :: 14 days/, bio (tamol) \ 50mg \ #50 \ 5x per week \ morning noon and evening \ 14 days/, bio (tamol) + 50mg + #50 + 5x per week + morning noon and evening + 14 days/,

这是从我的数据库返回的示例数据。这就是为什么我使用explode将此数据分离为数组数据的原因。

最佳答案

您在数据库中有20个记录,想要从第一个记录到第十个记录显示page 1,从第十一个记录到第二十个记录显示page 2

使用page 1,添加SQL LIMIT 0, 10

使用page 2,添加SQL LIMIT 10, 10

您可以了解以下内容:LIMIT $start, $limit

$start是数据库中的起始位置

$limit是您要检索的记录数

因此,我为您在URL传递page参数的示例。您得到page进行计算

$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
if ($page < 1) $page = 1;


现在,您将计算$start

$limit = 10;
$start = ($page - 1) * $limit;


因此,您拥有SQL:

$sql = "SELECT prescriptions FROM tblprescriptions WHERE `ID`='{$ID}' AND `appID`='{$appID}' LIMIT {$start}, {$limit}";


好看

关于php - 如何将表行分为2并显示为页面,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44196456/

10-13 01:39