Jump to content

[SOLVED] MySQL and PHP - If there is a record with a number, echo a word


Recommended Posts

Hi guys,

Ok basically I have a site that echos out things in the database, so it shows up like this

 

[username], Userlevel: [userlevel] (Number)

etc.

 

The userlevel shows up as a number, eg 9 for admin, 1 for normal user.

What I want it to do is when it sees a 9 in the database, actually show "Admin" instead of "9". And when it sees a 1 in the database, echo "Member" instead of "1".

 

eg:

 

Jonoc33, Userlevel: 9

Jonoc33, Userlevel: Admin

 

Jonoc33, Userlevel: 1

Jonoc33, Userlevel: Member

 

Thanks

well.........assuming you only have 2 user levels...member and admin

just echo it out like this

 

 

I'm sure you using a $row variable somewhere so

echo $row['username'] . ", ";
echo "Userlevel: ";
echo $row['userlevel'] != 9 ? "Member" : "Admin";

 

$results = mysql_query("SELECT username, userlevel FROM alpha_users");

while($values = mysql_fetch_array($results)){

     echo $values['username']."- Userlevel: ".$values['userlevel']."<br />";

}

 

This is what i'm using at the moment. Doesn't use $row.

just change this part

echo $values['username']."- Userlevel: ".$values['userlevel']."

to this

echo $values['username'] . "- ";
echo "Userlevel: ";
echo $values['userlevel'] != 9 ? "Member" : "Admin";

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.