Jump to content

[SOLVED] variable and if


onthespot

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/169590-solved-variable-and-if/
Share on other sites

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"; }

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.