This question already has answers here:
mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc… expects parameter 1 to be resource or result
(32个答案)
4年前关闭。
遇到以下问题并保持获取错误:
警告:mysqli_fetch_array()期望参数1为mysqli_result,
给定布尔值
这指向
我通常会说这是查询中的错误,但是我自己运行它,没有问题。
现在到您的代码
如果您在问题中发帖,这说明您自己无法解决问题,我会相应地修改答案,直到我们解决您的问题。
带有错误msg的完整代码
您的SQL语法有误。查看与您的MySQL服务器版本相对应的手册,以找到在第12行的''附近使用的正确语法
(32个答案)
4年前关闭。
遇到以下问题并保持获取错误:
$query = ("SELECT post_ID FROM Post WHERE Post_Title LIKE'%$Main_Search%'
AND Area_ID=$ID_Area");
$result = mysqli_query($con, $query);
while ($row = mysqli_fetch_array($result)){
$ID_Posts= $row['post_ID'];
$queryA =("SELECT * FROM Media
WHERE Post_ID =$ID_Posts
AND (Date_Created BETWEEN '$DateFrom' AND '$DateTo')
AND ( Media_Type = '$Film'
OR Media_Type ='$Photo'
OR Media_Type = '$Text'
OR Media_Type = '$Audio'
)
AND ( Outcome_Needs = '$Needs'
OR Outcome_Skills ='$Skills'
OR Outcome_Difference = '$Difference'
OR Outcome_Place = '$Place'");
$result2 = mysqli_query($con, $queryA);
while ($row2 = mysqli_fetch_array($result2)){
$Title = $row2["Media_Title"];
$Desc = $row2["Media_Description"];
echo $Title."<br/>";
echo $Desc."<br/>";
}
}
警告:mysqli_fetch_array()期望参数1为mysqli_result,
给定布尔值
这指向
while ($row2 = mysqli_fetch_array($result2))
行。我通常会说这是查询中的错误,但是我自己运行它,没有问题。
最佳答案
您似乎无视某些实际信息的所有要求,这是我的第一个想法。
在所有情况下查询总是出错,即我们凡人犯错,有时MySQL或comms或..也是如此。因此,检查每个对mysqli_
函数的调用是否顺利完成是一个好主意。
因此,为了“教人钓鱼”而不是“给他一条鱼”,我添加了一些代码来检查这些mysqli
调用
因此,首先在进行测试时(尤其是在托管服务器上进行测试时),最好将这两行添加到导致问题的脚本中
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
现在到您的代码
$query = ("SELECT post_ID FROM Post WHERE Post_Title LIKE'%$Main_Search%'
AND Area_ID=$ID_Area");
$result = mysqli_query($con, $query);
if ( ! $result ) {
echo mysqli_error($con);
exit;
}
while ($row = mysqli_fetch_array($result)){
$ID_Posts= $row['post_ID'];
$queryA =("SELECT * FROM Media
WHERE Post_ID =$ID_Posts
AND (Date_Created BETWEEN '$DateFrom' AND '$DateTo')
AND ( Media_Type = '$Film'
OR Media_Type ='$Photo'
OR Media_Type = '$Text'
OR Media_Type = '$Audio'
)
AND ( Outcome_Needs = '$Needs'
OR Outcome_Skills ='$Skills'
OR Outcome_Difference = '$Difference'
OR Outcome_Place = '$Place'");
$result2 = mysqli_query($con, $queryA);
if ( ! $result2 ) {
echo mysqli_error($con);
exit;
}
while ($row2 = mysqli_fetch_array($result2)){
$Title = $row2["Media_Title"];
$Desc = $row2["Media_Description"];
echo $Title."<br/>";
echo $Desc."<br/>";
}
}
如果您在问题中发帖,这说明您自己无法解决问题,我会相应地修改答案,直到我们解决您的问题。
带有错误msg的完整代码
include("inc/db.inc.php");
$Needs = $_POST['Needs'];
if (!in_array($Needs, array('Y', 'N')))$Needs = 'N';
$Skills = $_POST['Skills'];
if (!in_array($Skills, array('Y', 'N')))$Skills = 'N';
$Difference = $_POST['Difference'];
if (!in_array($Difference, array('Y', 'N')))$Difference = 'N';
$Place = $_POST['Place'];
if (!in_array($Place, array('Y', 'N')))$Place = 'N';
If (isset($_POST['Film'])){
$Film = "Film";
}else{
$Film = "";
}
If (isset($_POST['Photo'])){
$Photo = "Photo";
}else{
$Photo = "";
}
If (isset($_POST['Text'])){
$Text = "Text";
}else{
$Text = "";
}
If (isset($_POST['Audio'])){
$Audio = "Audio";
}else{
$Audio = "";
}
$DateFrom=$_POST['Datefrom'];
$DateTo=$_POST['Dateto'];
$Main_Search = $_POST['Main_Search'];
$ID_Area = $_POST['Area_ID'];
$query = ("SELECT post_ID FROM Post WHERE Post_Title LIKE'%$Main_Search%'
AND Area_ID=$ID_Area");
$result = mysqli_query($con, $query);
if ( ! $result ) {
echo mysqli_error($con);
exit;
}
while ($row = mysqli_fetch_array($result)){
$ID_Posts= $row['post_ID'];
$queryA =("SELECT * FROM Media
WHERE Post_ID =$ID_Posts
AND (Date_Created BETWEEN '$DateFrom' AND '$DateTo')
AND ( Media_Type = '$Film'
OR Media_Type ='$Photo'
OR Media_Type = '$Text'
OR Media_Type = '$Audio'
)
AND ( Outcome_Needs = '$Needs'
OR Outcome_Skills ='$Skills'
OR Outcome_Difference = '$Difference'
OR Outcome_Place = '$Place'");
$result2 = mysqli_query($con, $queryA);
if ( ! $result2 ) {
echo mysqli_error($con);
exit;
}
while ($row2 = mysqli_fetch_array($result2)){
$Title = $row2["Media_Title"];
$Desc = $row2["Media_Description"];
echo $Title."<br/>";
echo $Desc."<br/>";
}
}
Notice: Undefined index: Skills in /home/biggerstor/domains/ourbiggerstory.com/public_html/testsearch.php on line 7
Notice: Undefined index: Difference in /home/biggerstor/domains/ourbiggerstory.com/public_html/testsearch.php on line 9
Notice: Undefined index: Place in /home/biggerstor/domains/ourbiggerstory.com/public_html/testsearch.php on line 11
您的SQL语法有误。查看与您的MySQL服务器版本相对应的手册,以找到在第12行的''附近使用的正确语法
关于php - 嵌套的Mysqli连接,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32252657/
10-11 04:44