我的代码有问题, 我试图从我的数据库中的多表格中获取更多内容,但代码不起作用。
这是我得到的警告
警告:mysqli_fetch_array()期望参数1为mysqli_result, 给出的布尔值 第45行的C:\ wamp \ www \ Leerjaar2 \ myband2SlideOut \ model \ getuser.php
$q = $_GET['q'];
$con = mysqli_connect('localhost','root','','myband');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"myband");
$sql="SELECT title.newsarticles, content.newsarticles, information.newsarticles, title.band, information.band FROM newsarticles FULL OUTER JOIN band ON newsarticles.title=band.title LIKE '%$q%'"; //wildcard
//$sql="SELECT * FROM newsarticles WHERE title LIKE '%$q%'"; //wildcard
$result = mysqli_query($con,$sql);
if (!$sql) {
printf("Error: %s\n", mysqli_error($con));
exit();
}
echo "<table>
<tr>
<th>Title</th>
<th>Content</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" .$row['title']. "</td>";
echo "<td>" .$row['content']. "</td>";
}
echo "</table>";
mysqli_close($con);
答案 0 :(得分:0)
您的查询是:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="sample" type="checkbox">
<p id="hidethis">
hide me
</p>
请在$sql="SELECT title.newsarticles, content.newsarticles,
information.newsarticles, title.band, information.band FROM newsarticles
FULL OUTER JOIN band ON newsarticles.title=band.title LIKE '%$q%'" //wildcard
之后使用列名称,如下所示:
ON newsarticles.title=band.title
SQL LIKE语法
where column_name LIKE '%$q%'"