[PHP] Simple & Troublesome
Hello RaGEZONE :thumbup1:
I am stuck on the IF function in PHP. I am trying to write something so simple but failing, so if any of you could help I would be greatfull.
I would like to write something like this... I have writen it in Puseado code.
Code:
IF user_id has badge_code in database then give this badge else give the other badge
Re: [PHP] Simple & Troublesome
Ohh.. now I understand.. Whoops.. Well, you have to tell us more info.. Like is it using a MySQL database, etc.
Re: [PHP] Simple & Troublesome
PHP Code:
$default_badge = 'CRAP_BADGE_CODE';
$query = mysql_query('SELECT `badge_code` FROM `users` WHERE `user_id` = "'.$user_id.'"') or die(mysql_error());
if(mysql_num_rows($query)>0)
{
$row = mysql_fetch_assoc($query);
if(strlen($row['badge_code'])>0)
{
$users_badge = $row['badge_code'];
} else $users_badge = $default_badge;
} else $users_badge = $default_badge;