Yes, well but you don't want to set the Admin field to Yes or No for all new users as well right? As it's user 'independent', not depending on what user, it's a global option you want to set so it would be weird to set it for each user and beside that it would be able to cause errors as it will select only ONE row (member) its value for the field 'Admin', so when there are more members with different values for that field it can lead to errors/selecting the wrong value.
So what I'd suggest is creating another table with all options for your blog, which can beside this option as well provide you the ability to add & check more options for your blog easily.
Example of table:
Table name: options
field1
name: ID
type: 250(INT)
auto-increment & Primary Key
field2
name: opt_name
type: 20(VARCHAR)
field3
name: opt_value
type: 250(VARCHAR)
Add a row for the 'admin' option
Set: field 'opt_name' = 'admin' , 'opt_value' = 'Yes' (or 'No')
Example of script:
<?php
$check_admin = mysql_query("SELECT opt_value FROM options WHERE opt_name = 'admin' "); //select the value of the option 'admin'
$opt_admin = mysql_fetch_assoc($check_admin); //get the result
$opt_admin = $opt_admin['opt_value']; //get the value of the option
if($opt_admin == 'Yes') {
//show the link
}
?>
It's also possible in another way, by adding inside the WHERE clause: & opt_value = 'Yes'
And then just counting the rows found as result using mysql_num_rows. If this results in a number higher than 0 ( if properly done it should be 0 or 1, 1 if the row was foujnd with as value 'Yes', 0 if the rows wasn't found with the value 'Yes' ( so it contains another value: 'No' assumed )).
2nd method:
<?php
$check_admin = mysql_query("SELECT opt_value FROM options WHERE opt_name = 'admin' AND opt_value ='Yes' "); //select the value of the option 'admin'
$opt_admin = mysql_num_rows($check_admin); //count the rows found
if($opt_admin > 0) { //if any rows where found with option name = 'admin' and option value 'Yes'
//show the link
}
?>
ANOTHER method would be using COUNT, but I guess 2 methods is enough :D
Just use one of them and you should be fine :).
Table SQL
CREATE TABLE IF NOT EXISTS `options` (
`id` int(250) NOT NULL AUTO_INCREMENT,
`opt_name` varchar(20) NOT NULL,
`opt_value` varchar(250) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
INSERT INTO `options` (`id`, `opt_name`, `opt_value`) VALUES
(1, 'admin', 'Yes');
Note: Would rather use something like 0 or 1 to indicate the admin field to be 'Yes' (true = 1) or 'No' (false = 0), but doesn't matter too much I guess.
Edited by webcodez, 16 February 2010 - 08:24 AM.