jonoc33 Posted October 28, 2007 Share Posted October 28, 2007 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 Link to comment https://forums.phpfreaks.com/topic/75068-solved-mysql-and-php-if-there-is-a-record-with-a-number-echo-a-word/ Share on other sites More sharing options...
Zane Posted October 28, 2007 Share Posted October 28, 2007 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"; Link to comment https://forums.phpfreaks.com/topic/75068-solved-mysql-and-php-if-there-is-a-record-with-a-number-echo-a-word/#findComment-379664 Share on other sites More sharing options...
jonoc33 Posted October 28, 2007 Author Share Posted October 28, 2007 $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. Link to comment https://forums.phpfreaks.com/topic/75068-solved-mysql-and-php-if-there-is-a-record-with-a-number-echo-a-word/#findComment-379665 Share on other sites More sharing options...
Zane Posted October 28, 2007 Share Posted October 28, 2007 just change this part echo $values['username']."- Userlevel: ".$values['userlevel']." to this echo $values['username'] . "- "; echo "Userlevel: "; echo $values['userlevel'] != 9 ? "Member" : "Admin"; Link to comment https://forums.phpfreaks.com/topic/75068-solved-mysql-and-php-if-there-is-a-record-with-a-number-echo-a-word/#findComment-379667 Share on other sites More sharing options...
jonoc33 Posted October 28, 2007 Author Share Posted October 28, 2007 Worked, thanks Link to comment https://forums.phpfreaks.com/topic/75068-solved-mysql-and-php-if-there-is-a-record-with-a-number-echo-a-word/#findComment-379668 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.