douanrang4728 2016-04-13 08:51
浏览 56
已采纳

获取循环值,发送到另一个页面并使用该值调用catch数据

I use session to send that value to other page, but mysql syntax does not display the data using that value. It doesnt show the error on MySQL syntax. Can someone help me? and Explain why mysql syntax cannot read the session? or I need to assign new variable for session on the pakejlist.php page?

the value already call from DB and display on A HREF link on food.php , i want to get that value on pakejlist.php mysql syntax.

and what I achieve is nothing.. the syntax just fine but the data doesnt came out.

//food.php
<?php include("../kahwin/Connections/conn.php"); ?>

<!DOCTYPE html>
<html>
<head>
    <title>Kahwin Ringkas</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

</head>
<body>

<nav class="navbar navbar-inverse">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>                        
      </button>
      <a class="navbar-brand" href="/kahwin/index.php">Walimatul Urus</a>
    </div>
    <div class="collapse navbar-collapse" id="myNavbar">
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
      </ul>
    </div>
  </div>
</nav>

<div class="container">  
<div class="page-header">
  <h1>Carian Katering</h1>
</div>

  <?php
    session_start();
    $_SESSION['id'] = $row['v_id'];
    mysql_select_db($database_conn, $conn);
    $sql = mysql_query("SELECT * FROM vendor WHERE type = 'Katering'") or die (mysql_error());
    while ($row = mysql_fetch_array($sql)) {
  ?>
    <div class="col-md-4">
      <?php echo '<img src="data:image;base64, '.$row['img'].'" class="img-thumbnail">' ?>
      <h4><?php echo $row['companyName']?></h4>
      <p><?php echo $row['address']?>, <?php echo $row['code']?> <?php echo $row['city']?>, <?php echo $row['state']?><br><?php echo $row['contact']?><br><?php echo $row['email']?><br></p>
      <a href="pakejlist.php" value="<?php echo $row['v_id']?>">View Package</a><br>
    </div>
    <?php }
    ?>
</div>

</body>
</html>



        //pakejlist.php


    <?php include("../kahwin/Connections/conn.php"); ?>
<!DOCTYPE html>
<html>
<head>
    <title>Kahwin Ringkas</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

</head>
<body>

<nav class="navbar navbar-inverse">
  <div class="container-fluid">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>                        
      </button>
      <a class="navbar-brand" href="/kahwin/index.php">Walimatul Urus</a>
    </div>
    <div class="collapse navbar-collapse" id="myNavbar">
      <ul class="nav navbar-nav navbar-right">
        <li><a href="#"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
      </ul>
    </div>
  </div>
</nav>

<!-- Page Content -->
    <div class="container">

        <!-- Page Heading -->
        <div class="row">
            <div class="col-lg-12">
                <h1 class="page-header">Senarai Pakej</h1>
            </div>
        </div>
        <!-- /.row -->

        <!-- Project One -->
        <?php
            //$vid = $_REQUEST['id'];
            session_start();
            mysql_select_db($database_conn, $conn);
            $sql = mysql_query("SELECT * FROM pakej WHERE v_id = '" .$_SESSION['id']. "' ") or die (mysql_error());
            while ($result = mysql_fetch_array($sql)) {
        ?>
        <div class="row">
            <div class="col-md-6">
                <h3><?php echo $result['name_p']?></h3>
                <h4>$ <?php echo $result['harga']?></h4>
                <p><?php echo $result['descr']?></p>
                <a class="btn btn-primary" href="#">Add to cart <span class="glyphicon glyphicon-chevron-right"></span></a>
            </div>
            <div class="col-md-5"></div>
        </div>
        <?php }
        ?>
        <!-- /.row -->

        <hr>

</body>
</html>
  • 写回答

1条回答 默认 最新

  • dtmtu02882 2016-04-13 11:44
    关注

    In food.php, you are initialising session variable $_SESSION['id'] = $row['v_id'] , outside mysql_fetch_array loop. So $row['v_id'] is empty. Also if you initialize that from within the loop, it will be overwritten and will have the value from the last row.

    In the loop,

    <a href="pakejlist.php" value="<?php echo $row['v_id']?>">View Package</a><br>
    

    The value in anchor tag does not mean anything. It is not valid. So you can try this instead..

    <a href="pakejlist.php?v_id=<?php echo $row['v_id']?>">View Package</a><br>
    

    And in the pakejlist.php you will have change to

    $sql = mysql_query("SELECT * FROM pakej WHERE v_id = '" .$_GET['v_id']. "' ") or die (mysql_error());
    

    Hope this helps...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥18 模拟电路问题解答有偿
  • ¥15 Matlab在app上输入带有矩阵形式的初始条件发生错误
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题