duanmianxue2687 2013-04-01 09:07
浏览 41
已采纳

从数据库中选择下拉类别后如何从mysql表中显示图像?

I want to show a category based shopping items with images on web page that can be found in the most Online shopping sites.I crated two mysql tables: Ist with id, category_name and 2nd with id, categoryid, product, image_path. I am able to display all product images at a time on page, but I don't know how to show product images of a single category selected from a dropdown list with submit button at the top of the page. I hope my point is clear to all otherwise feel free to ask me.

Below I attached my code that shows all the product images on my php page at a time without any dropdown list. Any ideas and advice on doing this is welcome.

 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
 <title>Untitled Document</title>
 <style type="text/css">
  ul, li {
 list-style-type:none;
 }

ul.display {
width: 500px;
}

ul.display li { 
float: left;  
width: 100px; 
height: 120px;
margin-left: 5px; 
margin-right: 5px;
margin-bottom: 5px;
position: relative;
vertical-align:middle;
text-align:center;
}
ul.display li a img {
 width: 94px; 
height: 114px;
display: inline; 

}

 </style>
 </head>

  <body>

  <div align="center">
 <?php  
  include('connect.php'); 
   $SQL = "SELECT * from becuart";
    $result = mysql_query( $SQL );
    echo "<ul class='display'>";
    while( $row = mysql_fetch_array( $result ) ) {
    $filepath = $row["path"];

    echo "<li>";
    echo "<a href=\"$filepath\"><img src=\"$filepath\" border=\"0\"></a>";
    echo "</li>";
     }
    echo "</ul>";
    ?>
   </div>

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

2条回答 默认 最新

  • dphphvs496524 2013-04-01 10:42
    关注

    Because it's way too long -> new answer:

    <?php
    include 'dbconnect.php';
    ?>
    
    <form name="product" method="post" action="">
    <table align="right" width="10%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td>Category</td>
    <td>
    <select name="category">
    
    <?php
    $sql = "SELECT id, art_name, path FROM category;";
    $result = mysql_query($sql);
    while ($row = mysql_fetch_assoc($result)) {
    ?>
    
    <option value="<?= $row['id']; ?>"><?= $row['art_name']; ?></option>
    
    
    <?php } ?>
    </select>
    </td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td><input name="go" type="submit" value="Go" /></td>
    </tr>
    </table>
       </form>
    <div align="center">
    
     <ul class='display'>
     <?php
     $id = (int)$_POST['category'];
     $sql_search = "SELECT id, art_name, path FROM category WHERE id = $id";
     $search = mysql_query($sql_search);
     if (isset($_POST['go'])) {
     while ($row = mysql_fetch_assoc($search)) {
         ?>
    
    
    <li><a href="<?= $row['path']; ?>"><img src="<?= $row['path']; ?>" border="0"></a></li>
    <?php }
    
    }
    
    else {
    
    }
    
    
    ?>
    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值