如何将id获取到另一个页面并使其显示基于id的值


How to get id to another page and make it show value based on id

我已经参考了这篇文章如何在按钮点击中获得行ID?但仍然无法加载值,我不知道为什么。我很确定这个id已经在profile.php上被正确捕获了。下面是我的代码:

hanj.php
  style type="text/css">
      .buttonize {
        text-decoration: none;
        border: 1px solid #ccc;
        background-color: #efefef;
        padding: 10px 15px;
        -moz-border-radius: 11px;
        -webkit-border-radius: 11px;
        border-radius: 11px;
        text-shadow: 0 1px 0 #FFFFFF;
      }
     <?php require_once('Connections/conn.php');?>
    </style>
    <table border="1" cellpadding="5" cellspacing="2" width="600">
    <tr>
      <th>Vendor Id</th>
        <th>Kategori</th>
        <th>Nama Vendor</th>
        <th>Alamat</th>
        <th>Poskod</th>
        <th>Bandar</th>
         <th>Negeri</th>
         <th>No</th>
         <th>Email</th>
    </tr>

     <?php
     session_start();
     $_SESSION['profile']= $row ['v_id'];
    mysql_select_db ($database_conn,$conn);
    $query="SELECT v_id,type,companyName,address,code,city,state,contact,email FROM vendor";
    $result=mysql_query($query) or die(mysql_error());
    while($row=mysql_fetch_array($result))
    {
         echo "</td><td>";
        echo $row['v_id'];
        echo "</td><td>";
        echo $row['type'];
        echo "</td><td>";
        echo $row['companyName'];
        echo "</td><td>";
        echo $row['address'];
        echo "</td><td>";
        echo $row['code'];
        echo "</td><td>";
         echo $row['city'];
        echo "</td><td>";
         echo $row['state'];
        echo "</td><td>";
        echo $row['contact'];
        echo "</td><td>";
        echo $row['email'];
        echo "</td><td>";
        print '<center><a href="profile.php?id='.$row['v_id'].'" class="buttonize">View</a></center>';
        echo "</td></tr>";
    }
    ?>

 profile.php
    <?php require_once('Connections/conn.php'); ?>
    <html>
      <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Casado</title>
          <script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
          <script type="text/javascript" src="http://netdna.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
          <link href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
          <link href="http://pingendo.github.io/pingendo-bootstrap/themes/default/bootstrap.css" rel="stylesheet" type="text/css">
    <div class="container">
    <div class="col-md-12">
    <div class="col-md-2"></div>
    <div class="col-md-8">
    <table class="table table-bordered">
                  <thead>
                    <tr>
                      <th>Pakej</th>
                      <th>Image</th>
                      <th>Harga</th>
                      <th>Vendor Id</th>
                    </tr>
                  </thead>
                  <tbody>
                  <?php
                  session_start();            
                   mysql_select_db ($database_conn,$conn);
                   $vid = $_SESSION['profile'];
                   $sql = mysql_query("SELECT * from item where v_id = '$vid' ") or die (mysql_error());
                   while($res = mysql_fetch_array($sql)) {
                    ?>


                    <tr>
                      <td><?php echo $res['pakej'] ?></td>
                      <td><?php echo '<img src="data:image;base64,'.$res['image'].'" class="img-thumbnail">' ?></td>
                      <td><?php echo $res['harga'] ?></td>
                      <td><?php echo $res['v_id'] ?></td>
                    </tr>
                   <?php }
                   ?>
                  </tbody>
                </table>
                </div>
                <div class="col-md-2"></div>
                </div>
                </div>
    </body>
    </html>

顺便说一句,没有语法错误

profile.php中使用$_REQUEST['id']而不是$_SESSION['profile'],它应该可以工作。

在profile.php中,使用$_GET引用传入的"id"。即更换以下线路

$vid = $_SESSION['profile'];

用这个。

$vid = $_GET['id'];

希望这能有所帮助。

Bikash Paul在上面回答了这个问题,他建议将$_SESSION['profile']更改为$_REQUEST['id']

不要使用$vid = $_SESSION['profile'];,而是使用$vid = $_GET['profile'];,如果不起作用,则使用print_r($_GET)或print_r;向我们展示的详细信息