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 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启