weixin_33737774 2015-03-27 18:59 采纳率: 0%
浏览 22

PHP查询的Ajax菜单

Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and clarify the problem by editing this post.

Closed 5 years ago.

UPDATED

Have now got this far with this and think I am getting stuck right at the end!! I have now got both menus being processed by "process.php" and am outputting my queries back into index.php.

process.php

<?php
$menu1 = $_POST["menu1"];
$menu2 = $_POST["menu2"];

if($menu1 == 0) {
    $sql = "SELECT * FROM Language WHERE ID = " . $menu2;   
} else if($menu1 == 1) {
    $sql = "SELECT * FROM Mathematics WHERE ID = " . $menu2;
} else if($menu1 == 2) {
    $sql = "SELECT * FROM Culture WHERE ID = " . $menu2;
}

echo $sql;

?>

index.php

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <script type='text/javascript' src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script>
<script type='text/javascript'>
$(window).load(function(){
var data = {
            Language:       ["","Noun Game","Phonetic Noun Box"],
            Mathematics:    ["","Number Rods","Sandpaper Numerals"],
            Culture:        ["","Concept of Time-Clock"]
}
// populate menu1
for (var i in data) {
    $('#menu1').append('<option>' + i + '</option>');
}
// populate menu2 based on menu1 value
$('#menu1').change(function() {
    var key = $(this).val();
    $('#menu2').empty();
    for (var i in data[key]) {
        $('#menu2').append('<option>' + data[key][i] + '</option>');
    }
}).trigger('change');
});//]]>

</script>
</head>
<body>
<form id="form" action="process.php" method="post">
  <select id="menu1" name="menu1"></select>
  <select id="menu2" name="menu2"></select>

 <input id="submit" type="submit" value="ENTER" />
 
</form>
<div id="resultsContainer"></div>


<script>
    $(document).ready(function(){
       //alert('jQuery loaded');
        $('#form').submit(function(event){
            event.preventDefault;
            menu1value = $('#menu1')[0].selectedIndex;
            menu2value = $('#menu2')[0].selectedIndex;
            $.post('process.php',{menu1:menu1value,menu2:menu2value}).done(function(data){
                alert(data);
            })
            return false;
        })
    })
</script>

</body>
</html>

Now I just need to output queries in a table on index.php. Think this will be just about looping through the output but I'm not sure... any help please.

</div>
  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 GEO下载数据的处理报错 :函数‘Meta’标签‘"data.frame"’找不到继承方法,如何解决?
      • ¥15 DLNM模型是否可以用二分类变量作为y变量
      • ¥15 android object box 一个实体多个表怎么写
      • ¥15 temux 启用docker 服务失败
      • ¥15 Flask 使用celery发送邮件出现‘目标计算机积极拒绝‘
      • ¥60 老人用的sd卡在手机里面不知道操作了什么,导致图片和视频变成了文件,取下sd卡连接电脑就是图中的样子,后缀改为.jpg才可以,需要用系统的画图软件才能打开,文件属性还是文件,有没有批量操作的解决办法
      • ¥15 超时跳出方法代码的返回值问题
      • ¥15 汇编语言程序设计设计,ascii码求数,再求数的BCD码
      • ¥30 Mask rcnn训练自己的数据集出现问题!
      • ¥20 研究人工智能时的几个问题