我有这个简单的搜索表单,但没有返回任何内容。当我尝试var_dump($ser)
时显示null
。知道为什么会这样吗?
include 'include/db.php';
$sql = mysqli_query($conn, "SELECT caption,name FROM images WHERE caption LIKE '%$_GET[caption]%' LIMIT 0,1");
$caption = $sql['caption'];
$name = $sql['name'];
while($ser = mysqli_fetch_array($sql)){
$out .= "<div id=\"picture\">";
$out .= "<img style=\"width:100%;margin:0 auto;\" src=\"/upload/".$ser['name']."\" /><br />";
$out .= "<div id=\"caption\">";
$out .= "<h1>" . $ser['caption'] . "</h1>";
$out .= "</div><br />";
}
这是表格
<form action="../search.php" method="get">
<input type="text" name="caption" size="15">
<input type="submit" value="Search">
</form>
非常基本,但仍然很难理解错误。
答案 0 :(得分:1)
请试试这个
$result= mysqli_query($conn, "select caption,name from images where caption like '%'") or die (mysqli_error());
while($line = mysqli_fetch_array($result))
{
echo $line['caption'].$line['name']."<br/>";
}
检查您是否有错误或某些结果
答案 1 :(得分:0)
$caption = $_GET['caption'];
$sql = mysqli_query($conn, "SELECT caption,name FROM images WHERE caption LIKE '%'".$caption."'%' LIMIT 0,1");
while($ser = mysqli_fetch_array($sql)){
echo $ser['name']." ".$ser['caption'];
}