doujionggan9570 2013-04-03 07:00
浏览 9
已采纳

如何在php中显示页面加载的固定图像?

I have a php page where user can select one category via dropdown list and after clicking 'go' button the relative images for that category will display on page below the dropdown list from database. This works fine. Now I want to display the images on page load for the 1st dropdown list category everytime then after based on user choice. I think my point is clear to all. for example, 1st category in the dropdown is Featured art, on loading the php page images related to Featured art always display on page. After that user can change it by changing the category from dropdown. Help me please. Here is my complete code :

 <body>
 <?php
 include ('connect-db.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 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, categoryid, path FROM list WHERE categoryid = $id";
  $search = mysql_query($sql_search);
   if (isset($_POST['go'])) {
   while ($row = mysql_fetch_assoc($search)) {
  ?>


  <li><a href="<?= $row['path']; ?>" class="highslide" onclick="return hs.expand(this)"><img src="<?= $row['path']; ?>" border="0"></a></li>
  <?php }

  }

  else {

   }


    ?>
    </ul>
   </div>
   </body>

Thanks in advance!:)

  • 写回答

1条回答 默认 最新

  • douqiang3768 2013-04-03 07:29
    关注

    You may try to use GET request instead of POST. Using this you may check like:

    <?php
    
    $get_id = $_GET['category'];
    if($get_id == null){
        $get_id = <default-value-say-1>;
    }
    $id = (int)$get_id;
    
    ?>
    

    Also, in the dropdown, set the default / first category selected.

    When the user selects another option, redirect to url?category=<selected-id>

    This is not a copy-paste solution, please take this as a starting point and follow the best-practices for development in PHP or any PHP framework of your choice.

    Hope this helps!

    Vivek

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

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题