【问题标题】:Open web page according to html table data [closed]根据html表格数据打开网页[关闭]
【发布时间】:2017-07-13 01:40:43
【问题描述】:

我有一个通过 PHP 从 mysql 数据库表中填充的 HTML 表,其中包含 8 个不同的值。 我需要打开第二个页面并将我单击的值中的任何一个传递给它,以便从数据库中查询另一个。 到目前为止,我可以通过 href 打开第二页,但我可以解决参数问题。 谁能帮我解决这个问题?

代码:

<html>
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>

    <?php
    include "ligabd.php";//connects to the server
    if(!$l)
    {
        die("Ligação sem sucesso: ".mysql_error());
    }
    else
    {            
        $query="SELECT escalao FROM escaloes ORDER BY idescaloes ASC";
        $result=  mysqli_query($l, $query);                       
    ?>
    <link href="style.css" rel="stylesheet" type="text/css" />
    <table id="t01" align="center">
     <br>
     <br>
     <br>
     <br>
     <tr>
      <td align="center">Escalões</td>
      </tr>

    <?php
        while ($record=  mysqli_fetch_array($result))
        {
            $r=$record['escalao'];
            ?>
            <tr>
            <td>
            <a href="pag_escalao_mensalidade.php?escalao=">
            <?php 
            echo $record['escalao'];
            ?>
            </a>
            </td>
            </tr>
            <?php
        }                       
    }
    ?>
    </table>
</body>

【问题讨论】:

标签: php html url html-table href


【解决方案1】:

你应该在你的表中使用 id 并使用这个:

$query="SELECT id, escalao FROM escaloes ORDER BY idescaloes ASC";
...
while ($record=mysqli_fetch_assoc($result))  // Fetch assoc!
...
<a href="pag_escalao_mensalidade.php?id=<?= $record['id'] ?>"><?= $record['escalao'] ?></a>
....

在第二页,你再次获取记录

$query='SELECT * FROM escaloes WHERE id=' . intval( $_GET['id'] );

【讨论】:

  • 谢谢哈斯。我做了你的建议,它有效。
【解决方案2】:

这是错误的:

<a href="pag_escalao_mensalidade.php?escalao=">
<?php 
echo $record['escalao'];
?>

应该是

    <a href="pag_escalao_mensalidade.php?escalao=<?php 
                                                 ^^---
    echo $record['escalao'];
    ?>"><?php echo $record['escalao'] ?>
      ^^^^^^^---

注意指示的更改

【讨论】:

    猜你喜欢
    • 2014-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多