My “users” table structure is :
--
-- Table structure for table `users`
--
CREATE TABLE `users` (
`user_id` int(11) NOT NULL auto_increment,
`email` varchar(255) NOT NULL default '',
`passwd` varchar(50) NOT NULL default '',
`name` varchar(100) NOT NULL default '',
`access_lvl` tinyint(4) NOT NULL default '1',
PRIMARY KEY (`user_id`),
UNIQUE KEY `uniq_email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
--
There are 3 access_lvl value :
access_lvl [1] = “User”
access_lvl [2] = “Moderator”
access_lvl [3] = “Administrator”
My SQL query is :
$usersql = "SELECT * FROM users";
$result = mysql_query($usersql)
or die("Invalid query: " . mysql_error());
I display the result within table, using this :
<?php echo $row['access_lvl']; ?>
The result in a row is : 3, 1, 1
Question:
How can I display the value instead of the data itself - I mean instead of 3,1,1 - It will display Administrator, User, User.
My Attempt - that did not give result as what I want :
<?php
$access_lvl=' ';
if ($access_lvl=="1"){
echo "User";
}elseif($access_lvl=="2"){
echo "Moderator";
}else{
echo "Administrator";
}
?>
Any help will be appreciated