我使用get方法从mysql数据库获取值我从url传递survey_id和question_id
如下 http://myserver.com/emrapp/surveyAnswersScreenOne.php?survey_id=1,question_id=1
但是它给出了错误
我的php代码在下面给出了
$query = mysql_query("SELECT * from survey_Answers where survey_Id='".$survey_id."' AND question_Id='".$question_id"' ");
$rows = array();
while($row = mysql_fetch_assoc($query)) {
$rows[] = $row;
}
echo json_encode($rows);
答案 0 :(得分:2)
此行有错误,显示:
$question_id"' "
应该是
$question_id . "'"
答案 1 :(得分:0)
你应该用&分隔获取变量不,在网址中。
答案 2 :(得分:0)
那是因为你应该在url参数之间使用&
而不是,
http://myserver.com/emrapp/surveyAnswersScreenOne.php?survey_id=1&question_id=1
$survey_id = mysql_real_escape_string($_GET['survey_id']);
$question_id = mysql_real_escape_string($_GET['question_id']);
答案 3 :(得分:0)
GET参数通常用&
而不是,
分隔。所以你的链接看起来应该更像这样:
http://myserver.com/emrapp/surveyAnswersScreenOne.php?survey_id=1&question_id=1
另外,请注意GET变量不会自动转换为PHP变量。你需要从$_GET
数组中取出它们:
$survey_id = $_GET['survey_id']
答案 4 :(得分:0)
你没有传递在url中分隔的值逗号。你有使用&在网址中
http://myserver.com/emrapp/surveyAnswersScreenOne.php?survey_id=1&question_id=1
答案 5 :(得分:0)
$query = mysql_query("SELECT * from survey_Answers where survey_Id='".$survey_id."' AND question_Id='".$question_id"'");
你忘记了在$question_id
- >之后连接字符串的重点。这应该可以解决您的问题:
$query = mysql_query("SELECT * from survey_Answers where survey_Id='".$survey_id."' AND question_Id='".$question_id."'");
无论如何,还要考虑清理你的网址 - > http://xkcd.com/327/
答案 6 :(得分:0)
$query = mysql_query("SELECT * from survey_Answers where survey_Id='".$survey_id."' AND question_Id='".$question_id."' ");
缺少一个点!
答案 7 :(得分:0)
网址和查询错误
http://myserver.com/emrapp/surveyAnswersScreenOne.php?survey_id=1&question_id=1
AND
$question_id . "' "