-2

目前,我的查询与我网站上的所有成员相呼应,它会显示他们的个人资料图片并链接到他们的个人资料页面。假设我有 50 个成员,并且查询限制为 60,那么我想用默认图像填充空白空间并链接到默认页面,所以我正在寻找一个 if 语句来说明用户是否不存在然后回显这张照片而是链接?

有人可以告诉我我哪里出错了。谢谢

<?php
        $user_set = get_users();
        while ($users = mysql_fetch_array($user_set)) {



            if (!file_exists($users)) {
    $users = "data/photos/0/_default.jpg";
}



        $age = age_from_dob($users['dob']);
             echo "
            <div class=\"sugarushcase\">
            <a href=\"profile.php?id={$users['id']}\"><img width=80px height= 80px src=\"data/photos/{$users['id']}/_default.jpg\" class=\"boxgrid\"/></a><h58> {$users['first_name']} {$users['last_name']}</h58><br/><br/><h52>{$users['contact_number']}<br/><br/> ".$age.", From {$users['location']}</h52>

            </div>";
        }
    ?> 
4

2 回答 2

0

类似于以下内容?

<?php


    $user_set = get_users();
    $user_count = mysql_num_rows($user_set);
    while ($users = mysql_fetch_array($user_set)) {

        if (!file_exists($users)) {
            $users = "data/photos/0/_default.jpg";
        }

        $age = age_from_dob($users['dob']);

        echo "<div class=\"sugarushcase\">
        <a href=\"profile.php?id={$users['id']}\"><img width=80px height= 80px src=\"data/photos/{$users['id']}/_default.jpg\" class=\"boxgrid\"/></a><h58> {$users['first_name']} {$users['last_name']}</h58><br/><br/><h52>{$users['contact_number']}<br/><br/> ".$age.", From {$users['location']}</h52>
        </div>";

    }

    // if there were less than 60 users we need some default profiles to fill the spaces
    if($user_count < 60){
        // how many default spaces do we need?
        $default_profiles_needed = 60 - $user_count;        
        for($i = 1; $i <= $default_profiles_needed; $i++){
            echo "<div class=\"sugarushcase\">
                    <a href=\"default.php\">
                        <img width=80px height= 80px src=\"default.jpg\" class=\"boxgrid\"/>
                    </a>
                </div>";
        }
    }


?> 
于 2013-02-08T14:35:10.827 回答
0

你可以找这个

   <?php
    $user_set = get_users();
    if (!$user_set) {

                 $users = "data/photos/0/_default.jpg";
                   }
                   else {
    while ($users = mysql_fetch_array($user_set)) {


    $age = age_from_dob($users['dob']);
         echo "
        <div class=\"sugarushcase\">
        <a href=\"profile.php?id={$users['id']}\"><img width=80px height= 80px src=\"data/photos/{$users['id']}/_default.jpg\" class=\"boxgrid\"/></a><h58> {$users['first_name']} {$users['last_name']}</h58><br/><br/><h52>{$users['contact_number']}<br/><br/> ".$age.", From {$users['location']}</h52>

        </div>";
    } }
?> 
于 2013-02-08T14:35:43.237 回答