此查询有效,但未显示“没有结果”'信息。它应该是回声而不是第6行的退出吗?
<?php
$key = $_GET['key'];
$array = array();
$con = mysql_connect("localhost","xxx","xxx");
$db = mysql_select_db("xxx",$con);
$query = mysql_query("select * FROM byartist2columns WHERE byartistnd LIKE '%{$key}%'");
if( mysql_num_rows($query) == 0 ) exit( "No results" );
while($row=mysql_fetch_assoc($query))
{
$array[] = $row['byartist'];
}
echo json_encode($array);
?>
JAVASCRIPT
<script>
$(document).ready(function() {
$('input.typeahead').typeahead({
name: 'typeahead',
remote: 'r-search.php?key=%QUERY',
limit: 150
});
});
</script>
答案 0 :(得分:0)
更改条件如下。
if( mysql_num_rows($query) == 0 ) { $array[] = "No results"; }