douwei9973 2015-01-02 16:03
浏览 40
已采纳

在php中按下按钮时选择该特定id

I am trying to send the id from one page to other and i have achieved that but how do i make sure that when the show is pressed of a particular column only that id is sent.Here is my code. This is index.php.It displays the rows and a show button against each row.

    <?php session_start(); ?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <link   href="css/bootstrap.min.css" rel="stylesheet">
    <script src="js/bootstrap.min.js"></script>
    </head>

    <body>
    <div class="container">
            <div class="row">
                <h3>Restaurant Categories</h3>
            </div>
            <div class="row">
            <p> <a href="create_categories.php" class="btn btn-success">Create</a> </p>
                <table class="table table-striped table-bordered">
                  <thead>
                    <tr>
                      <th>ID</th>
                      <th>Name</th>
                      <th>Description</th>
                    </tr>
                  </thead>
                  <tbody>
                  <?php
                   include 'database.php';
                   $pdo = Database::connect();
                   $sql = 'SELECT * FROM Categories';
                   $result = $pdo->query($sql);
                   foreach ($pdo->query($sql) as $row) {
                            echo '<tr>';
                            echo '<td>'. $row['C_id'] . '</td>';
                            echo '<td>'. $row['C_name'] . '</td>';
                            echo '<td>'. $row['C_description'] . '</td>';
                            echo '<td><a class="btn" href="show_items.php">Shitems</a>     </td>';

                            $_SESSION["id"] = $row['C_id'];     <-----I am saving the id here.But it only saves the latest id
                            echo $_SESSION["id"];
                            echo '</tr>';
                   }
                   Database::disconnect();
                  ?>
                  </tbody>
            </table>
        </div>
       </div> <!-- /container -->
    </body>
  </html>
  • 写回答

3条回答 默认 最新

  • duanjiu1003 2015-01-02 16:07
    关注

    Just embed the ID in the url as a query string:

    echo '<td><a class="btn" href="show_items.php?id=' . $row['C_id'] . '">Shitems</a>     </td>';
                                                 ^^^^^^^^^^^^^^^^^^^^ 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊