doujian0265 2013-02-08 14:25
浏览 27

如果查询存在,如果不存在,则回显这个吗?

At the moment i have query that echos out all the members on my site, it displays their profile picture and link to their profile page. say ive got 50 members and the query is limited to 60 then i want to fill the blank space with a default image and link to a default page, so im looking for an if statement to say if the user doesnt exist then echo out this photo and link instead?

can someone please show me where im going wrong. thanks

<?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>";
        }
    ?> 
  • 写回答

2条回答 默认 最新

  • doog1092 2013-02-08 14:35
    关注

    Something along the lines of the following?

    <?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>";
            }
        }
    
    
    ?> 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单