dpt62283 2018-02-15 17:27
浏览 68

如何使用AJAX基于MySQL查询设置选择框和输入框的值

I have a web page with a large number of select boxes plus a few other types of inputs. I want to populate these select boxes and input boxes with values held in a MySQL database based on the values selected in two of the select boxes. I have tried to use AJAX to request the data but cannot see how to return the data held in a database to a specific select box from the server php script. jscript used to request the data is as follows

<script>
function venueChange(str) {
    if (str == "") {
        document.getElementById("Venue").innerHTML = "";
        return;
    } else { 
        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
                document.getElementById("Player1").innerHTML = this.responseText;
            }
        };
        var opponent_name = document.getElementById("Opponents").value
        var variables = "venue_name=str&opponent_name=Hello World";
        xmlhttp.open("GET","getTeamPHP?" + variables,true);
        xmlhttp.send();
    }
}
</script>

The getTeamPHP files is as follows;

<?php

require '../../configure.php';

$q = intval($_GET['venue_name']);
$v = $_GET['opponent_name'];
$database = "matchmanagementdb";
$con = mysqli_connect(DB_SERVER, DB_USER, DB_PASS,$database);
if (!$con) {
    die('Could not connect: ' . mysqli_error($con));
}

//mysqli_select_db($con,$database);
$sql="SELECT * FROM user WHERE Opponents = '".$q."' AND Venue = '".$v."'";
$result = mysqli_query($con,$sql);


while($row = mysqli_fetch_array($result)) {

    echo  document.getElementById("Player1").innerHTML = $row['FirstName'] ;

}

mysqli_close($con);
?>
  • 写回答

1条回答 默认 最新

  • dongting7352 2018-02-16 17:55
    关注

    I have decided that the solution lies in creating three scripts to; 1) read the search details 2) search the database and populate the form 3) allow updates. As per http://www.dynamicdrive.com/forums/showthread.php?45895-How-to-populate-php-html-form-with-MySQL-data. So closing this question.

    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法