TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Advanced PHP Programming (http://www.talkphp.com/advanced-php-programming/)
-   -   Matching an ID within an array (http://www.talkphp.com/advanced-php-programming/5213-matching-id-within-array.html)

paulOr 01-09-2010 12:57 AM

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 01-09-2010 01:12 AM

solved this problem with in_array().
amazing!


All times are GMT. The time now is 01:50 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0