【问题标题】:If no results found, display (message)如果未找到结果,则显示(消息)
【发布时间】:2012-05-31 15:17:59
【问题描述】:

如果在搜索查询中未找到任何结果,则尝试显示一条消息。

这是我的代码的一个简短示例。

$sql = "SELECT * FROM details WHERE ID =1"

$res =& $db->query($sql);
if (PEAR::isError($res)) {
    die($res->getMessage());
}

while($row = $res->fetchRow())
{
     echo 'results'
    {

任何帮助将不胜感激!谢谢

【问题讨论】:

    标签: php sql error-handling pear


    【解决方案1】:

    DB_result 有一个名为numRows() 的方法,所以你可以检查一下

    if($res->numRows() == 0)

    http://pear.php.net/package/DB/docs/latest/DB/DB_result.html#methodnumRows

    获取结果集中的行数

    返回:行数。失败时的 DB_Error 对象。

    您无需担心DB_Error,因为它已经在

    PEAR::isError($res)

    【讨论】:

      猜你喜欢
      • 2014-09-21
      • 1970-01-01
      • 1970-01-01
      • 2013-12-25
      • 2013-09-24
      • 2017-09-28
      • 2016-12-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多