我继续得到这个错误=警告:mysql_fetch_array()期望参数1是资源,在此代码中给出布尔值:`
<script>
//this will trigger automatically when they change the first select box
$('#dateFilter').on('change', function(event){
if($(this).val() == 'dateFilter'){
$("#ajax_reply_div").empty()
}else{
var values = $(this).serialize();
$.ajax({
url: "AdvanceOption.php",
type: "post",
data: values,
success: function(data){
$("#ajax_reply_div").empty().append(data);
},
error:function(){
$("#ajax_reply_div").empty().append('something went wrong');
}
});
}
});
</script>
<div id='center'>
<?php include "header.php"; // display menu options ?>
<form id = "project_form" method="post">
<div id="searchPanel">
<?php
echo "Choose a date";
$something_date = $sample->retrieveFilterDate();
$data_date = array();
echo "<select id='dateFilter' class='dateFilter' name='dateFilter'>";
while($row_date = mysql_fetch_assoc($something_date)){
array_push($data_date, $row_date);
echo "<option value='".$row_date['date']."' >".$row_date['date']." </option>";
}
echo "</select>";
echo "\tChoose a place";
$something_place = $rm->retrieveFilterplace();
$data_place = array();
echo "<select id='placeFilter' class='placeFilter' name='placeFilter'>";
while($row_place = mysql_fetch_assoc($something_place)){
array_push($data_place, $row_place);
echo "<option value='".$row_place['placeNumber']."' >".$row_place['placeNumber']." </option>";
}
echo "</select>";
if((isset($_POST['dateFilter'])) && (isset($_POST['placeFilter']))){
$result = mysql_query("SELECT nameNumber,time,user_id * FROM table_something WHERE '".$_POST['dateFilter']."' AND '".$_POST['placeFilter']."' ");
echo "<option value=''>Select Your Album</option>";
while($row = mysql_fetch_array($result)){
echo "<option value='" . $row['nameNumber'] . "'>" . $row['time'] . "</option>";
}
}
?>
<div id="ajax_reply_div">
</div>
<input type="submit" value="Submit">
</div>
</form>`
错误在此行中($ row = mysql_fetch_array($ result)){。过程是用户将从两个选择选项中进行选择,然后单击提交按钮,然后将从两个选择选项中输出与选择用户相关的行。任何帮助将非常感激。
答案 0 :(得分:0)
您收到此错误是因为$result
是布尔值。您可以阅读有关该功能如何工作的文档here on the PHP documentation site。
$result = mysql_query("SELECT nameNumber,time,user_id * FROM table_something WHERE '".$_POST['dateFilter']."' AND '".$_POST['placeFilter']."' ");
您可能会收到此错误,因为您的SELECT
查询形成错误,而是生成错误。
您不仅需要删除*
,如下所示,而且您的WHERE
子句可能无效,因为您实际上并未比较任何值。阅读有关WHERE子句here
$result = mysql_query("SELECT nameNumber,time,user_id FROM table_something WHERE '".$_POST['dateFilter']."' AND '".$_POST['placeFilter']."' ");
您可能还想查看用于操作数据库的PDO或MySQLi扩展,因为mysql_*
函数现已弃用并将被删除(请参阅php manual page?上的大红框) 。另请参阅如何防止SQL Injection使代码更安全