Cagecrawler Posted November 15, 2006 Share Posted November 15, 2006 My code[code]<?phpinclude("include/connect.php");$user_level = mysql_query("SELECT user_level FROM users WHERE username='$username'");$user_level = mysql_fetch_assoc($user_level);echo $user_level;if ($user_level == 2){ echo("<a href=\"admin/admin.php\" target=\"main\">Admin</a><br/>");}?>[/code]When the script is run, I get the word 'Array' from echo $user_level, rather than '2', the user's level. This means that the IF function is false and the link is not displayed. The echo is in there just to see what I'm outputting while writting the script. Why does it not output the right thing? Quote Link to comment Share on other sites More sharing options...
craygo Posted November 15, 2006 Share Posted November 15, 2006 That's because you need to pull the correct field from the array. try this[code]<?phpinclude("include/connect.php");$user_level = mysql_query("SELECT user_level FROM users WHERE username='$username'") or die (mysql_error());$row = mysql_fetch_assoc($user_level);echo $row['user_level'];if ($row['user_level'] == 2){ echo("<a href=\"admin/admin.php\" target=\"main\">Admin</a><br/>");}?>[/code]What this does is put the returning row into an array called $row. Then you call on your row by putting the row name between the brackets ie $row['user_level'].Ray Quote Link to comment Share on other sites More sharing options...
Cagecrawler Posted November 15, 2006 Author Share Posted November 15, 2006 Excellent, now works fine. Thanks! :) Quote Link to comment 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.