如果 mysql 表中不存在任何结果,则回显其他内容


If no results exist in mysql table echo something else?

有人可以帮我吗,我正在尝试根据我的"权限"表中每个用户的记录显示不同的图像。 我正在使用.

如果表中不存在记录,我想包含一个不同的文件路径,即

目前,如果用户权限设置为 1 或 0,它会显示结果,但我想这样做,以便在表中找不到结果时,它会默认显示一些内容。

法典:

<?php if (logged_in()) { 
    $account_perms = account_perms();
    while ($perms = mysql_fetch_array($account_perms)) {
    if ($perms['privellages'] == '1')  {
        if ( mysql_num_rows( $perms ) > 0 )
              include('includes/mod_profile/mod_photos/private.php'); 
    } 
    }
    $account_perms = account_perms();
    while ($perms = mysql_fetch_array($account_perms)) {
    if ($perms['privellages'] == '0')  {
     include('includes/mod_profile/mod_photos/private2.php'); 
    } 
    } 
    $account_perms = account_perms();
    while ($perms = mysql_fetch_array($account_perms)) {
      if($perms->num_rows > 0) {
         include('includes/mod_profile/mod_photos/private2.php'); 
      } 
    } 
} ?>

试试这个:

<?
if (logged_in()) {
    $account_perms = account_perms();
    if (mysql_num_rows($account_perms)) {
        while ($perms = mysql_fetch_array($account_perms)) {
            if ($perms['privellages'] == '1') {
                if (mysql_num_rows($perms) > 0)
                    include ('includes/mod_profile/mod_photos/private.php');
            }
        }
    } else {
        echo 'No records';
    }
    $account_perms = account_perms();
    if (mysql_num_rows($account_perms)) {
        while ($perms = mysql_fetch_array($account_perms)) {
            if ($perms['privellages'] == '0') {
                include ('includes/mod_profile/mod_photos/private2.php');
            }
        }
    } else {
        echo 'No records';
    }
    $account_perms = account_perms();
    if (mysql_num_rows($account_perms)) {
        while ($perms = mysql_fetch_array($account_perms)) {
            if ($perms -> num_rows > 0) {
                include ('includes/mod_profile/mod_photos/private2.php');
            }
        }
    } else {
        echo 'No records';
    }
}
?>