I'm setting up a menu structure using a recursive menu tree that works just fine. I want to be able to restrict the items in the menu by userID. I have some code that delivers the current users userID to a variable $currentUserID.
The problem that I'm having is that there seems to be no way to get this variable into the code to be read. Here's the broken code:
PHP Code:
<?php
$currentUserID = $row_currentUserRS['id'];
$parentid = 0; // assuming that 0 is the main category
get_sub_cats($parentid);
function get_sub_cats($parentid) {
$sql = "SELECT * FROM netContent WHERE parentID = $parentid ";
$run = mysql_query($sql);
echo '<ul>';
while ($rec = mysql_fetch_assoc($run)) {
if ($rec['userID'] == $currentUserID) {
echo '<li /><a href ="',$rec['pageType'], $rec['id'],'">', $rec['linkName'], '</a>';
get_sub_cats($rec['id']);
}
}
echo '</ul>';
}
?>
If I change the if statement to
Code:
if ($rec['userID'] == 35) {
for example, I get what I want. I also get what I want if I remove the if statement and add
to the query, but whenever I try and use the $currentUserID variable I get nothing. No list. No error.
Any suggestions would be appreciated. I've been fooling with this for far too long.