Jump to content

use results data via $results[fieldname]


newbeee

Recommended Posts

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
}

Link to comment
https://forums.phpfreaks.com/topic/141600-use-results-data-via-resultsfieldname/
Share on other sites

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.

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.