dqvrlgi3247 2012-10-22 23:37
浏览 7

在页面加载时加载php表单搜索结果

I have a simple php form that allows users to choose from a drop-down list of subject areas to return a set of databases (ex. http://library.wabash.edu/biology.php). As you can see, nothing is returned until a selection is made and Submit is clicked. Is it possible to have a set of databases already load when the page loads (biology databases would load on the Biology Dept page, etc.) but then also allow the users to make another selection, as I have now? My inexperience shows here, so apologies in advance.

<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
   <select name="choice" id="choice">
      <option value="Biology">Biology</option>
      <option value="Chemistry">Chemistry</option>
      <option value="Computer Science">Computer Science</option>
      <option value="Mathematics">Mathematics</option>
      <option value="Medicine">Medicine</option>
      <option value="Physics">Physics</option>
</select>

   <input type="submit" name="submit" value="Go" style="margin-left: 10px">
   <input type="submit" name="reset" value="Clear" style="margin-left: 10px">
   <input type="hidden" name="submitted" value="true"/>
</form>

<?php
if(isset($_POST['submit']))   {

   $choice=$_POST['choice'];

   $localhost="localhost";
   $username="xxxxxxx";
   $password="xxxxxxx";
   $database="xxxxxxx";

   $linkid=mysql_connect($localhost,$username,$password);  
   @mysql_select_db($database) or die( "Unable to select database");

   mysql_select_db("databases",$linkid);
   $resultid=mysql_query("SELECT  name, mobile, app, tutorial, help
                          FROM databaselist
                          WHERE dept
                          LIKE '%{$choice}%'
                          ORDER BY sortname ASC", $linkid);

   echo"<table>";
   while ($row = mysql_fetch_row($resultid))
      {
         echo"<tr>";
         foreach ($row as $field)
            {
               echo"<td>$field</td>";
            }
         echo"</tr>";
      }
   echo"</table>";
   mysql_close($linkid);
}
?>
  • 写回答

3条回答 默认 最新

  • duan_88598 2012-10-22 23:49
    关注

    As you have now if u don't intend to use javascript, you can do one thing:

    1- remove the validation of $_POST['submit'], you can check only for the $choice=$_POST['choice'] variable. 2- change the choice variable from $_POST array to $_GET array, that way you can build a link something like. --> mypage.com/index.php?choice=Biology. having this you will be able to fill the list on the biology page for example, and also let the user choose any other choice.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。