我试图让php ajax搜索数据库中发布的文章,但它只给我:没有结果消息。我已经测试了与数据库和选择查询的连接,并且它可以工作。 这是代码:
<?php
require_once('dbconn.php');
$s = $_GET["s"];
$livesearch = '';
if (strlen($s) > 0)
{
$result = mysql_query("select * from articles where art_sts='1' ORDER BY title");
if ($result != FALSE)
{
foreach($result as $row)
{
if (stristr($row['title'], $s))
{
if ($livesearch == '')
{
$livesearch = '<a href="upload_pdf/'.$row["fisier"].'?id='.$row["id"].' "> '.htmlentities($row["title"], ENT_QUOTES, "UTF-8").'</a>';
}
}
}
}
}
if ($livesearch == '')
{
$respond="No results...";
}
else
{
$respond = $livesearch;
}
echo $respond;
?>
答案 0 :(得分:1)
您实际上并未提取您要输出的数据。你需要添加这样的东西......
while($row = mysql_fetch_assoc($result)) {
if (stristr($row['title'], $s))
{
if ($livesearch == '')
{
$livesearch = '<a href="upload_pdf/'.$row["fisier"].'?id='.$row["id"].' "> '.htmlentities($row["title"], ENT_QUOTES, "UTF-8").'</a>';
}
}
}