Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.