php - 从数据库中选择数据到 html 表并链接到其他页面 (<a>)

标签 php html mysql mysqli

在表中,我想要链接 a,单击转到其他页面并选择此类别中的所有产品 我想放一个,但我不知道怎么做,因为从数据库中选择的 td 可以是多个

$sql = 'SELECT categorie.id,name,username FROM categorie,user
        where user.id = categorie.added_by ';
$result = $mysqli->query($sql);
?>

<table class="data-table">
    <h1>Categorie List<h1>
    <thead>
        <tr>
            <th>Id</th>
            <th>Username</th>
            <th>Added By</th>
        </tr>
    </thead>
    <tbody>
        <?php
        if($result ==  false)echo "errrrr";
        else{
            while ($row = mysqli_fetch_array($result))
            {
                echo '<tr>
                <td>'.$row['id'].'</td>
                // here i want link <a> when click go to other page and 
                // select all products in this categorie
                <td>'.$row['name'].'</td>
                <td>'.$row['username'].'</td>

                </tr>';

            }
        }
        ?>
    </tbody>
</table>

在表格中,我想要链接a,点击转到其他页面并选择此类别中的所有产品

最佳答案

您的链接应该是这样的:

...
<td><a href="otherpage.php?categorie='.$row['id'].'">'.$row['name'].'</a></td>
...

然后在otherpage.php中,您可以从$_GET['categorie']获取类别ID。

关于php - 从数据库中选择数据到 html 表并链接到其他页面 (<a>),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46553048/

相关文章:

mysql - phpmyadmin 无法识别我的 sql

php - Laravel 5.2 - PHPExcel_Writer_Exception : Unable to load PDF Rendering library in

php - 在 Apache 上强制使用 HTTPS 并产生奇怪的结果

php - 如何提高亚马逊sqs排队速度?

php - 使用功能验证管理员权限失败

javascript - 如何从 JS 更改 RangeSlider 颜色

mysql - 如何测试MySQL事务?

php - 如何让 mysqli 在 SQL 语句中使用 DELIMITER?

javascript - 单击时触发 JavaScript 操作?

mysql - UPDATE vs COUNT vs SELECT 性能