如何在页面中划分echo数据库

a5g8bdjr  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(261)

这里有一个代码,它使用echo在数据库中显示我的表的内容。我的问题是我不知道任何方法来显示它的页面,因为它显示所有的数据。这是我当前的php代码

<table border="0" cellspacing="0" cellpadding="4" class="tablecontainer">
<tr>
<td class="table_titles">ID</td>
<td class="table_titles">Date and Time</td>
<td class="table_titles">Frequency</td>
<td class="table_titles">Wave Height</td>
<td class="table_titles">Longitude</td>
<td class="table_titles">Latitude</td>
</tr>
<?php
include('connection.php');
$result = mysqli_query($con,'SELECT * FROM data ORDER BY id DESC');

$oddrow = true;
while($row = mysqli_fetch_array($result))
{
if ($oddrow)
{
$css_class=' class="table_cells_odd"';
}
else
{
$css_class=' class="table_cells_even"';
}
$oddrow = !$oddrow; 
echo "<tr>";
echo "<td '.$css_class.'>" . $row['id'] . "</td>";
echo "<td '.$css_class.'>" . $row['date_time'] . "</td>";
echo "<td '.$css_class.'>" . $row['height'] . "</td>";
echo "<td '.$css_class.'>" . $row['frequency'] . "</td>";
echo "<td '.$css_class.'>" . $row['latitude'] . "</td>";
echo "<td '.$css_class.'>" . $row['longitude'] . "</td>";
echo "</tr>"; 
}

mysqli_close($con);
?>
</table>
kulphzqa

kulphzqa1#

<table border="0" cellspacing="0" cellpadding="4" class="tablecontainer">
    <tr>
    <td class="table_titles">ID</td>
    <td class="table_titles">Date and Time</td>
    <td class="table_titles">Frequency</td>
    <td class="table_titles">Wave Height</td>
    <td class="table_titles">Longitude</td>
    <td class="table_titles">Latitude</td>
    </tr>
    <?php
    include('connection.php');
$page = ($_REQUEST[page])?$_REQUEST[page]:1;
$recordperpage=5;
$start = ($_REQUEST[page]-1) * $recordperpage;
    $result = mysqli_query($con,"SELECT * FROM data ORDER BY id DESC LIMIT {$start}, {$recordperpage}");

    $oddrow = true;
    while($row = mysqli_fetch_array($result))
    {
    if ($oddrow)
    {
    $css_class=' class="table_cells_odd"';
    }
    else
    {
    $css_class=' class="table_cells_even"';
    }
    $oddrow = !$oddrow; 
    echo "<tr>";
    echo "<td '.$css_class.'>" . $row['id'] . "</td>";
    echo "<td '.$css_class.'>" . $row['date_time'] . "</td>";
    echo "<td '.$css_class.'>" . $row['height'] . "</td>";
    echo "<td '.$css_class.'>" . $row['frequency'] . "</td>";
    echo "<td '.$css_class.'>" . $row['latitude'] . "</td>";
    echo "<td '.$css_class.'>" . $row['longitude'] . "</td>";
    echo "</tr>"; 
    }

    mysqli_close($con);
    ?>

<a href="yourfile.php?page=1">Page 1</a>
<a href="yourfile.php?page=2">Page 2</a>

您需要将yourfile.php替换为实际文件

相关问题