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


how to show fixed images on pageload in php?

我有一个php页面,用户可以通过下拉列表选择一个类别,点击'go'按钮后,该类别的相对图像将显示在页面下拉列表从数据库。这很好。现在我要显示的图像页面加载上的第一个下拉列表类别,然后每次基于用户的选择之后。我想我的观点大家都明白了。例如,下拉列表中的第一个类别是特色艺术,在加载php页面时,与特色艺术相关的图像总是显示在页面上。之后,用户可以通过从下拉菜单中更改类别来更改它。请帮帮我。下面是我的完整代码:

 <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>

提前感谢!:)

您可以尝试使用GET请求而不是POST。你可以这样检查:

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

另外,在下拉菜单中,设置所选择的默认/第一个类别。

当用户选择其他选项时,重定向到url?category=

这不是复制粘贴解决方案,请以此为起点指出并遵循PHP或任何PHP开发的最佳实践框架的选择。

希望这对你有帮助!

Vivek