dt2015 2012-09-12 18:13
浏览 102

从sql获取数据到下拉列表(在html中选择\选项)

I am trying to build a drop down element in html, and to add the values according to user pre-choice. Lets say I have table with one col is game type ans second is a name field. So if the user first drop down choice is basketball - so another drop down list is opened with all the basketball fields as options.

so I have my html file which has inside this php lines:

$game_type = $_POST['gameType'];

$con = mysql_connect("localhost", "root", "Jbtraining1");
if (!$con)
    die('Could not connect: ' . mysql_error());

$db_selected = mysql_select_db("test_sport",$con);
$sql = ("SELECT * FROM fields WHERE game_type = '$game_type'");
$result = mysql_query($sql,$con);

while($row = mysql_fetch_array($result))
    echo "<option value='".$row['field_name_en']."'>" . $row['field_name_en'] . "</option>";
?>
</select>

but this lines does not work. I think most of the lines work well cause if i chage this line:

$game_type = $_POST['gameType'];

to let say to this line -

$game_type = "basketball";

It does work just fine.

Thanks

  • 写回答

2条回答 默认 最新

  • doufang1954 2012-10-18 22:07
    关注

    Change your file extension from .html to .php

    Hope this helps

    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集