0

我已经在不超过 2 小时前就这个问题发表了一篇文章,但我真的需要尽快完成。

我要做的是在苏格兰创建一个由32个不同位置的下拉容器。一个 div WHERE 位置 = 格拉斯哥。

目前我没有每个位置的 URL。

选择新选项时出现以下消息:“加载结果:成功 ||| 200 OK”

有人可以为我提供这个令人沮丧的难题的最后一块吗?

这是我正在使用的文件:

头文件.php

<html>
<head>
<script src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $('#location').change(function(){
    //Retrieve Content from the back-end PHP page, and pass the ID selected
    var url = 'location.php?location=' + $(this).val();
    $('#txtHint').load(url, function (response, status, xhr) { alert("Load result: " + status + " ||| " + xhr.status + " " + xhr.statusText); 
    });
  });
});    
</script>

</head>
<body>
    <div id="header">
        <div class="headerLeftContent">
            <select id="location">
                    <option value="Glasgow">Glasgow</option>
                    <option value="x">x</option>
                    <option value="test">test</option>
                    <option value="Edinburgh">Edinburgh</option>
            </select>
            <div id='txtHint'></div>
        </div>          
    </div>

</body>
</html>

位置.php

<?php
$connect = mysql_connect('xxx', 'xxx', 'xxx');
$select_db = mysql_select_db('xxx');

$location = $_REQUEST['location'];

$query = "SELECT * FROM podContent WHERE location = '.$location.'";

$result = mysql_query( $query, $connect );

while($row = mysql_fetch_array($result))
{
echo $row['text'];
}

?>

谢谢。

4

2 回答 2

0

两件事情:

  1. $query = "SELECT * FROM podContent WHERE location = '.$location.'";有两个额外的点。应该是$query = "SELECT * FROM podContent WHERE location = '$location'";
  2. 在使用$location来自用户的值之前,您应该使用mysql_real_escape_string(). 请注意,此函数已弃用,并将在 PHP 的未来版本中删除。您应该查看PDO并准备好声明。
于 2013-02-16T00:52:55.113 回答
0

纠正这个

$query = "SELECT * FROM podContent WHERE location = ".$location;
于 2013-02-15T23:08:33.353 回答