Hi,
I'm trying to understand why declaring a variable global within a function is not working. I have a function that displays a table of users and is supposed to set a global variable to true when called in order to let another function know whether or not to display a hyperlink. Here is what I have:
function display_users($user_array)
{
// display the table of users
// set global variable, so we can test later if this is on the page
global $user_table;
$user_table = true;
?>
<br />
<form name='user_table' action='delete_users.php' method='post'>
<table width=300 cellpadding=2 cellspacing=0>
<?php
$color = "#000000";
echo "<tr bgcolor='$color'><td><strong>User</strong></td>";
echo "<td><strong>Delete?</strong></td></tr>";
if (is_array($user_array) && count($user_array)>0)
{
foreach ($user_array as $user)
{
if ($color == "#cccccc")
$color = "#ffffff";
else
$color = "#cccccc";
// remember to call htmlspecialchars() when we are displaying user data
echo "<tr bgcolor='$color'><td><a href=\"$user\">".htmlspecialchars($user)."</a></td>";
echo "<td><input type='checkbox' name=\"del_me[]\"
value=\"$user\"></td>";
echo "</tr>";
}
}
else
echo "<tr><td>No users on record</td></tr>";
?>
</table>
</form>
<?php
}
function display_admin_menu()
{
?>
<a href="admin_member.php">Home</a> |
<?php
// only offer the delete option if user table is on this page
global $user_table;
if($user_table==true)
echo "<a href='#' onClick='user_table.submit();'>Delete User</a> | ";
else
echo "<font color='#cccccc'>Delete User</font> | ";
}
Thanks for any help,
Jason