TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-09-2010, 12:57 AM   #1 (permalink)
The Wanderer
 
paulOr's Avatar
 
Join Date: Nov 2007
Location: Edinburgh
Posts: 21
Thanks: 1
paulOr is on a distinguished road
Default Matching an ID within an array

I have been scratching my head with this one for a couple hours now. Heres my problem;

i have two databases;
1) Categories
2) Roles

within ROLES i have;
ADMIN(id:1), BLOG(id:2), CMS(id:3)

in CATEGORIES i have;
SECTION1, SECTION2, SECTION3

each CATEGORIE has different roles attached, for example;
SECTION1 can be viewed by ADMIN and CMS - 1,3
SECTION2 can be viewed by ADMIN and BLOG - 1,2
SECTION3 can be viewed by ALL - 1,2,3

I have been trying to show these roles in a checkbox format, for editing purposes.
However im not quite getting it right :(


PHP Code:
$roles_q mysql_query("SELECT * FROM `roles` ORDER BY `id`");
while(
$role mysql_fetch_array($roles_q)) {

## THESE ARE COMMA DELIMIED, LIKE SHOWN ABOVE IN EXAMPLES
$roles explode(',',$cat['roles']); 

## EXPLODE THE ROLE ID (?)
$role_role explode(',',$role['id']); // THESE ARNT EVEN COMMA DELIMINATED, IT JUST DIDNT LIKE $cat['roles'] ON ITS OWN

## NOW TO TRY MATCH THE CURRENT $cat['roles'] WITH THE $role['id']'S IN THE DATABASE
foreach($roles as $theroles) {
    if(
in_array($theroles$role_role)) {
        
$found[] = $role['id'];
    }                            } 
So we should end up with a list of ROLES that are in that categorie;

Code:
<p><input type="checkbox" id="role[]" name="role[]" value="<?php echo $role['id']; ?>" class="checkbox" <?php if($role['id'] == $role['id']) { echo 'checked="checked"'; } ?> /> <?php echo $role['name']; ?></p>
Think of this as a forum, where admins and mods can see some forums, but members cant see them. Its just like that what im trying to achive, but i havent done the front end part yet, this is just to allow me to change the permissions in the back end.

Any help would be appreciated.
__________________
paulOr.net
paulOr is offline  
Reply With Quote
Old 01-09-2010, 01:12 AM   #2 (permalink)
The Wanderer
 
paulOr's Avatar
 
Join Date: Nov 2007
Location: Edinburgh
Posts: 21
Thanks: 1
paulOr is on a distinguished road
Default

solved this problem with in_array().
amazing!
__________________
paulOr.net
paulOr is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Group Array "teams" and add up points godsdead General 3 07-15-2009 08:38 PM
Echo matching key in multidimention array Peuplarchie General 0 04-05-2009 08:31 AM
How to search array benton General 3 03-29-2009 12:31 AM
Array mess Killswitch Absolute Beginners 4 12-14-2008 07:35 AM
Part 1: Getting Started with Array Functions Wildhoney Absolute Beginners 6 10-01-2007 10:53 AM


All times are GMT. The time now is 04:36 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design