onthespot Posted August 10, 2009 Share Posted August 10, 2009 Hey guys, cant get this working. So I have a variable $ulevel = mysql_result($result,$i,"userlevel"); I want to have a second variable where it the first variable for the return of a number. So if ulevel = 9, echo Admin. $level = if $ulevel = 9; echo "Admin"; That didn't work. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/169590-solved-variable-and-if/ Share on other sites More sharing options...
KevinM1 Posted August 10, 2009 Share Posted August 10, 2009 First, this is a simple syntax error that can be avoided by reading the manual, or any of the millions of beginner tutorials found through a google search. Link to the manual page you want: http://us2.php.net/manual/en/control-structures.if.php Second, you don't need to assign a variable here. Simply: if ($ulevel = 9) { echo "Admin"; } Quote Link to comment https://forums.phpfreaks.com/topic/169590-solved-variable-and-if/#findComment-894713 Share on other sites More sharing options...
onthespot Posted August 10, 2009 Author Share Posted August 10, 2009 Thankyou, how would I fit it into the following? echo "<table cellspacing=\"3\" style='border: 1px dotted;' bgcolor=\"#eeeeee\">\n"; echo "<tr><td><b>Username</b></td><td><b>Level</b></td><td><b>Email</b></td></tr>\n"; for($i=0; $i<$num_rows; $i++){ $uname = mysql_result($result,$i,"username"); $ulevel = mysql_result($result,$i,"userlevel"); $email = mysql_result($result,$i,"email"); echo "<tr><td>$uname</td><td>[b]$ulevel[/b]</td><td>$email</td></tr>\n"; } echo "</table><br>\n"; where i have put bold, I want the following to happen if ($ulevel = 9) { echo "Admin"; } Also can I put several if statements in, for different numbers? Quote Link to comment https://forums.phpfreaks.com/topic/169590-solved-variable-and-if/#findComment-894716 Share on other sites More sharing options...
KevinM1 Posted August 10, 2009 Share Posted August 10, 2009 After you obtain the $ulevel, but before you echo the data, do something like: $level = ""; if ($ulevel == 9) { $level = "admin"; } Then, use $level as the echoed data. And, you can have an infinite number of if statements, or if/else statements. Quote Link to comment https://forums.phpfreaks.com/topic/169590-solved-variable-and-if/#findComment-894718 Share on other sites More sharing options...
onthespot Posted August 10, 2009 Author Share Posted August 10, 2009 Perfect, thankyou. Quote Link to comment https://forums.phpfreaks.com/topic/169590-solved-variable-and-if/#findComment-894728 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.