如何在执行插入查询后在php页面中添加产品

时间:2014-04-27 13:58:06

标签: php mysql

php文件

 <?php
 require_once('conn.php');
 $itemId= (\filter_input(\INPUT_GET,'itemId'));
 $sql="select img from getdesserticecream  where itemId='$itemId'";
 $res=mysqli_query($dbhandle,$sql);
 //$row=  \mysqli_fetch_array($res);
 //$subtitle=$row['subtitle'];
 $row= mysqli_fetch_assoc($res);
 //mysqli_close($dbhandle);
 header("Content-type: image");
 stripslashes($row['img']);
 ?>

<html>
<head>
    <title>Customer menu card</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width">
    <link rel="stylesheet" type="text/css" href="dessert.css">
</head>
<body>
    <form id='custdisp' name='custdisp' method='post' onload='return display()'  enctype="multipart/form-data">
        <script src="samcheck.js"></script>
        <div id="top">
        <?php session_start(); ?>
      <div id="toplbl">Welcome <?php  echo $_SESSION["name"]?></div>
      <?php session_start(); ?>
      <div id="toplbl1">This is Table Number <?php  echo $_SESSION["tnumber"]?></div>

      <input type="hidden" style="position: absolute;top:200px;" value="<?php echo $_SESSION["custno"]?>">
  </div>
    <div id="container">

        <div id="header" >
            <img id="headerimage" src="../samproject/contentimg.jpg" alt="image"/>
            <label id="headerlbl1">Order </label>
            <label id="headerlbl2">Eat</label>
            <label id="headerlbl3">Pay !!!! </label>
       </div>

        <nav>
        <ul>
            <li><a href='#'>Starter</a>           
                <ul>
                    <li><a href="customersvsoup.php">Veg</a></li>


                    <li><a href="customersnvsoup.php">NonVeg</a></li>
                </ul>
            </li>
            <li><a href="#">Main Course</a>
                <ul>
                    <li><a href="customermcvsundries.php">Veg</a></li>
                    <li><a href="customermcnvricedishes.php">NonVeg</a></li>
                </ul>
            </li>
            <li><a href="customerdicecream.php">Dessert</a></li>
        </ul>
    </nav> 
    <div id="content">
    <nav id="n1">
    <ul id="ul1">
    <li id="li1">    <a href="#">I want to see ----></a>

      <ul id="ul2"> 
          <li id="li2"><a href="customerdicecream.php">Ice cream</a></li>
          <li id="li3"><a href="customerdsalad.php">Salad and Cakes</a></li>
            <li id="li4"><a href="customerdshake.php">Milk shake</a></li>
        </ul> 
    </ul>
    </nav>  

  <div id="portfolio1">
  <?php  $sql1="select subtitle from dessert where itemId='oepd1007'";
  $res1=mysqli_query($dbhandle,$sql1);
  $row1= mysqli_fetch_array($res1);
  $subtitle1=$row1['subtitle'];?> <?php echo $subtitle1 ?></div>
  <div id="portfolio2">
  <?php  $sql2="select subtitle from dessert where itemId='oepd5148'";
  $res2=mysqli_query($dbhandle,$sql2);
  $row2= mysqli_fetch_array($res2);
  $subtitle2=$row2['subtitle'];?> <?php echo $subtitle2 ?></div>
  <div id="portfolio3">
  <?php  $sql3="select subtitle from dessert where itemId='oepd1004'";
  $res3=mysqli_query($dbhandle,$sql3);
  $row3= mysqli_fetch_array($res3);
   $subtitle3=$row3['subtitle'];?> <?php echo $subtitle3 ?></div>
   <div id="portfolio4">
  <?php  $sql4="select subtitle from dessert where itemId='oepd1008'";
  $res4=mysqli_query($dbhandle,$sql4);
  $row4= mysqli_fetch_array($res4);
  $subtitle4=$row4['subtitle'];?> <?php echo $subtitle4 ?></div>
  <div id="portfolio5">
  <?php  $sql5="select subtitle from dessert where itemId='oepd1522'";
  $res5=mysqli_query($dbhandle,$sql5);
 $row5= mysqli_fetch_array($res5);
 $subtitle5=$row5['subtitle'];?> <?php echo $subtitle5 ?></div>
 <div id="portfolio6">
  <?php  $sql6="select subtitle from dessert where itemId='oepd1002'";
  $res6=mysqli_query($dbhandle,$sql6);
  $row6= mysqli_fetch_array($res6);
  $subtitle6=$row6['subtitle'];?> <?php echo $subtitle6 ?></div>
  <div id="portfolio7">
  <?php  $sql7="select subtitle from dessert where itemId='oepd1003'";
  $res7=mysqli_query($dbhandle,$sql7);
  $row7= mysqli_fetch_array($res7);
  $subtitle7=$row7['subtitle'];?> <?php echo $subtitle7 ?></div>
  <div id="portfolio8">
  <?php  $sql8="select subtitle from dessert where itemId='oepd1001'";
  $res8=mysqli_query($dbhandle,$sql8);
  $row8= mysqli_fetch_array($res8);
  $subtitle8=$row8['subtitle'];?> <?php echo $subtitle8 ?></div>
  <div id="portfolio9">
  <?php  $sql9="select subtitle from dessert where itemId='oepd1005'";
  $res9=mysqli_query($dbhandle,$sql9);
  $row9= mysqli_fetch_array($res9);
  $subtitle9=$row9['subtitle'];?> <?php echo $subtitle9 ?></div>
  <div id="portfolio10">
  <?php  $sql10="select subtitle from dessert where itemId='oepd1010'";
  $res10=mysqli_query($dbhandle,$sql10);
  $row10= mysqli_fetch_array($res10);
  $subtitle10=$row10['subtitle'];?> <?php echo $subtitle10 ?></div>
  <div id="portfolio11">
  <?php  $sql11="select subtitle from dessert where itemId='oepd1011'";
  $res11=mysqli_query($dbhandle,$sql11);
  $row11= mysqli_fetch_array($res11);
  $subtitle11=$row11['subtitle'];?> <?php echo $subtitle11 ?></div>
  <div id="portfolio12">
  <?php  $sql12="select subtitle from dessert where itemId='oepd1006'";
  $res12=mysqli_query($dbhandle,$sql12);
  $row12= mysqli_fetch_array($res12);
  $subtitle12=$row12['subtitle'];?> <?php echo $subtitle12 ?></div>
  <ul id="grid">
  <li>
  <a href="samcheckdb.php?itemId=oepd1007">    <img src="getdesserticecreamimage.php?itemId=oepd1007" alt="image" id="img1"></a></li> 
<li>  <a href="samcheckdb.php?itemId=oepd5148"><img src="getdesserticecreamimage.php?itemId=oepd5148" alt="image" id="img2"></a></li> 
<li>  <a href="samcheckdb.php?itemId=oepd1004"> <img src="getdesserticecreamimage.php?itemId=oepd1004" alt="image" id="img3"></a> </li>
<li> <a href="samcheckdb.php?itemId=oepd1008">  <img src="getdesserticecreamimage.php?itemId=oepd1008" alt="image" id="img4" > </a></li> 
<li> <a href="samcheckdb.php?itemId=oepd1522"> <img src="getdesserticecreamimage.php?itemId=oepd1522" alt="image" id="img5" ></a> <li> 
<li><a href="samcheckdb.php?itemId=oepd1002">  <img src="getdesserticecreamimage.php?itemId=oepd1002" alt="image" id="img6" ></a> </li> 
<li> <a href="samcheckdb.php?itemId=oepd1003"> <img src="getdesserticecreamimage.php?itemId=oepd1003" alt="image" id="img7"> </a></li> 
<li> <a href="samcheckdb.php?itemId=oepd1001"> <img src="getdesserticecreamimage.php?itemId=oepd1001" alt="image" id="img8"></a></li> 
<li>  <a href="samcheckdb.php?itemId=oepd1005">   <img src="getdesserticecreamimage.php?itemId=oepd1005" alt="image" id="img9"></a> </li>
<li>  <a href="samcheckdb.php?itemId=oepd1010">   <img src="getdesserticecreamimage.php?itemId=oepd1010" alt="image" id="img10"></a> </li>
<li>  <a href="samcheckdb.php?itemId=oepd1011">   <img src="getdesserticecreamimage.php?itemId=oepd1011" alt="image" id="img11"> </a></li>
<li>  <a href="samcheckdb.php?itemId=oepd1006">   <img src="getdesserticecreamimage.php?itemId=oepd1006" alt="image" id="img12"></a> </li>
  </ul>

    </div>
    </div>
    </form> 
    </body>
    </html>

我从数据库中检索了所有图像并在php文件中显示,但是一旦我将它们插入数据库,我就需要将图像显示在这个文件中。

我是通过提供itemId来做到这一点,但我不知道如何提供$itemId并检索所有图片..

1 个答案:

答案 0 :(得分:0)

尝试此操作,在菜单关闭后立即输入此代码:

  /* Your menu code */
  </ul>
</nav> 

<?php
  $results = array();
  $res = mysqli_query($dbhandle,'select subtitle,itemId from dessert');
  # We are going to fetch all the subtitle and itemId from your table
  while($row= mysqli_fetch_array($res)){
    # And save it in an array
    $results[] = array('subtitle'=>$row['subtitle'],'itemId'=>$row['itemId']);
  }

 # Now, let's display the portfolio div elements first
 foreach($results as $key=>$val){
    echo "<div id='portfolio{$key}'>".$val['subtitle']."</div>";
 }

 # And then the images:
 echo "<ul id='grid'>";

 #using the same array again but this time it will be the itemId
 foreach($results as $key=>$val){
    echo '<li><a href="samcheckdb.php?itemId='.$val['itemId'].'"><img src="getdesserticecreamimage.php?itemId='.$val['itemId'].'" alt="image" id="img'.$key.'"></a></li>';
 }

 ?>

就这么简单。在所有数据库连接都很昂贵之后,您需要通过循环遍历公共模式来学习缩短代码 - 利用更多资源和时间。