newbeee Posted January 20, 2009 Share Posted January 20, 2009 get data from mysql and use it via... $results[fieldname] i have used it once but can not remember or find it on my sites code. what is the correct way to do this please. i hope to use this to simplify the permission section of my site. this is my database... CREATE TABLE IF NOT EXISTS `permissions` ( `username` text NOT NULL, `Some Menu` tinyint(4) NOT NULL, `Forum Menu` tinyint(4) NOT NULL, `Menu1` tinyint(4) NOT NULL, `Another Menu` tinyint(4) NOT NULL, `Menu2` tinyint(4) NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; -- -- Dumping data for table `permissions` -- INSERT INTO `permissions` (`username`, `Some Menu`, `Forum Menu`, `Menu1`, `Another Menu`, `Menu2`) VALUES ('Steph', 0, 1, 1, 0, 0), ('Terry', 0, 0, 0, 0, 0), ('Tom', 0, 0, 0, 0, 0), ('James', 0, 0, 0, 0, 0), ('Jason', 1, 1, 1, 1, 1), ('Tina', 0, 0, 0, 0, 0), ('Sue', 0, 0, 0, 0, 0), ('Tim', 0, 1, 0, 0, 0), ('David', 0, 0, 0, 0, 0), ('Lil', 0, 0, 0, 0, 0); then a user logs in and the database is got with the permissions the user can do. i would then use the following to find out if they can use that page or not if ($permissions[menu2] = '1') { //show menu } Quote Link to comment https://forums.phpfreaks.com/topic/141600-use-results-data-via-resultsfieldname/ Share on other sites More sharing options...
thepip3r Posted January 20, 2009 Share Posted January 20, 2009 if your conditional IF statement at the bottom of your post is related to the SQL INSERT you have above it, the reason your "$permissions" array doesn't have the 'menu2' element in it is because you're not querying for anything. your SQL INSERT does just that--adds information into a database. you need to run an alternate Select 'menu2' From permissions Where username='$some_user' and then use mysql_fetch_assoc() to get those entries. Quote Link to comment https://forums.phpfreaks.com/topic/141600-use-results-data-via-resultsfieldname/#findComment-741274 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.