如果mysql表中没有结果,则回显其他内容?

时间:2013-01-31 13:15:26

标签: php mysql

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

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

如果用户权限设置为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'); 
      } 
    } 
} ?>

1 个答案:

答案 0 :(得分:2)

试试这个:

<?
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';
    }
}
?>