2013-02-08 66 views
-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>"; 
     } 
    ?> 
+1

也許一'else' ...?您是否嘗試過學習基本PHP,閱讀文檔或一些教程? – Raekye 2013-02-08 14:27:06

回答

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>"; 
     } 
    } 


?> 
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>"; 
    } } 
?> 
相關問題