joeholdcroft Posted June 4, 2006 Share Posted June 4, 2006 Ok, so for a while I've been shooting myself over this script that I can't get to work, let me explain what I want it to do as simply as I can.I have a users table, with a column where the categories each user can post news in are stored, seperated by a comma, the category IDs are stored, not the category names.I want this script to first, check of the logged in user is an administrator, or a writer, if they are a writer, I want it to:Search through the users table for their user information, get the categories column and then display each of the categories they are allowed to post in in a drop-down select menu, and only the ones that have the ID in that column of their row on the users table, NOT all categories.And if they are an admin, it just displays all the categories in a drop-down menu.I have been fiddling with this for ages, but can't get it to work. The user i'm logged in as has the value "1, 3" for his categories column, and is a writer. So theoretically, it should show just Test 1 and Test 3 in the drop down menu, when in reality it shows Test 1(id=1), Test 2(id=2) and Test 3(id=3).This is the code:[code] <select name="category" class="form" id="category"><?php $userid = $_SESSION['userid']; if($_SESSION['rank'] == 'writer') { $result = mysql_query("SELECT categories FROM users WHERE id='$userid'") or die(mysql_error()); $usrcat = explode(",", $usrcat); foreach($usrcat as $cat) { $cat = trim($cat); $result = mysql_query("SELECT * FROM categories WHERE id='$cat'") or die(mysql_error()); while($eachcat = mysql_fetch_array($result)) { $catid = $eachcat['id']; $catname = $eachcat['name']; echo "<option value=\"$catid\">$catname</option>"; } } } elseif($_SESSION['rank'] == 'admin') { $result = mysql_query("SELECT * FROM categories") or die(mysql_error()); while($eachcat = mysql_fetch_array($result)) { $catid = $eachcat['id']; $catname = $eachcat['name']; echo "<option value=\"$catid\">$catname</option>"; } } ?> </select>[/code]Many thanks in advance guys, I'm intrigued as to what I'm doing wrong here, I don't get any error messages as such, just it shows all categories except just the 2 I want.Thanks!Joe Quote Link to comment https://forums.phpfreaks.com/topic/11169-phpmysql-select-menu/ Share on other sites More sharing options...
joeholdcroft Posted June 4, 2006 Author Share Posted June 4, 2006 Please ignore, just my luck to figure it out as soon as I make a post. Thanks :) Quote Link to comment https://forums.phpfreaks.com/topic/11169-phpmysql-select-menu/#findComment-41769 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.