Saturday, 15 January 2011

php - if query exists echo this if not then echo this? -



php - if query exists echo this if not then echo this? -

at moment have query echos out members on site, displays profile image , link profile page. ive got 50 members , query limited 60 want fill blank space default image , link default page, im looking if statement if user doesnt exist echo out photo , link instead?

can please show me 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.", {$users['location']}</h52> </div>"; } ?>

something along lines of 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.", {$users['location']}</h52> </div>"; } // if there less 60 users need default profiles fill spaces if($user_count < 60){ // how many default spaces 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>"; } } ?>

php mysql

No comments:

Post a Comment