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? Link to comment https://forums.phpfreaks.com/topic/27368-php-mysql-query/ 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 Link to comment https://forums.phpfreaks.com/topic/27368-php-mysql-query/#findComment-125152 Share on other sites More sharing options...
Cagecrawler Posted November 15, 2006 Author Share Posted November 15, 2006 Excellent, now works fine. Thanks! :) Link to comment https://forums.phpfreaks.com/topic/27368-php-mysql-query/#findComment-125153 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.