本文介绍了如果没有行计数,如何回显消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我从数据库中取回任何内容时,我试图回显没有找到记录消息。
I am trying to echo the message 'No records found' when I get nothing back from the database.
我做了一个行计数,行我有,但我似乎不能回应没有找到记录消息。是在错误的地方吗?
I have done a row count which shows me how many rows I have but I can't seem to echo the 'No records found' message. Is it in the wrong place? Will it not run for some reason?
<?php if(isset($search_results)){
foreach($search_results as $result) {
$rowcount = $result['rowcount'];
if(!$rowcount < 1) {
echo $rowcount;
echo '<div class="search_result"> <b>'.$result['title'].'</b><br />';
echo '<span class="search_result_url">'.$result['link'].'</span><br />';
echo $result['text'].'<br /></div>';
} else {
echo 'No records found.';
}
}
} else {
echo 'Use the search to find what you are looking for. Enter the term or keyord into the search box and press enter..';
}
?>
推荐答案
查看,使用 if()
查看您的 mysql_query()
是否返回任何结果:
Take a look at mysql_num_rows()
, and use an if()
to see whether your mysql_query()
returned any results:
$result = mysql_query("SELECT * FROM table");
if(!mysql_num_rows($result))
{
echo 'No results';
}
else
{
// Results - do stuff.
}
这篇关于如果没有行计数,如何回显消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!