Jump to content

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


jonoc33

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.