Jump to content

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.