douao2000 2017-12-15 09:13
浏览 64

单击另一页上的按钮时从表中回显值

Following is the table i created for displaying the Restaurant Name, Location and Menu for table owners. Now each of the row for the column Menu have Button as values. My table is ready with perfect values.

NOW MY PROBLEM IS HOW TO DO:-

Upon clicking the button corresponding to the each Restaurant, a new File(openmenu.php) will open and will echo the Restaurant Name, Mobile Number of that Restaurant and the menu. But so far, on clicking every Button ,I can only display above entries of the Last row of the table. Help Me Out. I am new to php.

table.php

<?php


include 'nav.php';
$sql = 'SELECT * FROM owners';

$query = mysqli_query($con, $sql);

if (!$query) {
die ('SQL Error: ' . mysqli_error($con));
}


?>

<html>
<head>
<link rel = "stylesheet" type = "text/css" href = "css/style.css">

<style> 
    .data-table{
 width: 1024px;
    margin-left: 150px;
    text-align:center;
     border: 1px solid firebrick;
    background-color: white;

}
td,th{
    border: 1px solid firebrick; padding: 3px 2px 1px 1px;
}


</style>
</head>

<body>

<div class="container">

<article>

<table class="data-table">

    <thead>
        <tr>

            <th>Restuarant Name</th>
            <th>Location</th>
            <th>Menu</th>
        </tr>
        <tr>

        </tr>
    </thead>
    <tbody>
    <?php

    while ($row = mysqli_fetch_array($query)){

   $_SESSION['resphone'] = $row['resphone'];
      $_SESSION['restaur'] = $row['restaur'];
        echo '<tr>


                <td>'.$row['restaur'].'</td>
                <td>'.$row['loc'].'</td>

                <td style="background-color:firebrick;"><form method="post" action="openmenu.php?id=$row[restaur]"><input value="<?php echo $restaur;?>" type="hidden">
 <input type="submit"  value="View"></form></td>
            </tr>';


    }


        ?>

            </tbody>

</table>


</form>







</article>



</div>

</body>
</html>

openmenu.php

<?php 


include('nav.php');


?>

<html>
<head>

 <link rel="stylesheet" href="css/style.css">
 <style>
table, td {
border: none;
 text-align: center;
    text-align-last: center;
 }

</style>
</head>
<body>

<div class="container">




<article>

<form  method="get" align="center"  action="" class="formwrap" enctype='multipart/form-data'>
<h1><?php $restaur = $_SESSION['restaur'];
echo $restaur ;?></h1>
<h1>Call to Order:</h1>
<?php $resphone = $_SESSION['resphone'];

echo $resphone;

?>

<br>
<br>
 <?php


 $sql = "select img from owners where restaur ='$restaur'";
 $result = mysqli_query($con,$sql);
 $row = mysqli_fetch_array($result);

 $image_src2 = "upload/".$row['img'];


?>
<img src='<?php echo $image_src2; ?>' >   

    </form>

</article>


 </div>

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

1条回答 默认 最新

  • dongzengzai4567 2017-12-15 09:19
    关注

    There are several ways you could solve this problem.

    You could make a <form> with your view button ( if this view button not already has a form ) and give this a method like: POST or GET.

    This would look like: <form method="POST"> or <form method="GET">

    Docs to POST and GET

    I think your view button could look something like this

    <form method="post" action="OtherPHPpage.php">
    <input type="hidden" name="view" value="<?php echo $row['resphone']; ?>">
    <input type="submit" value="View">
    </form>
    

    This will redirect you to your other page and you will be able to post the value of the hidden input type

    You can also use php sessions even though this is not the best solution in your case

    session_start();
    

    Put this on the top of your php page

    // set the session
    $_SESSION['variablename'] = $row['resphone'];
    
    // retrieve the session variable
    $whatever = $_SESSION['variablename'];
    
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大