Jump to content


Photo

[Solved]How would i do this if statement?


  • Please log in to reply
5 replies to this topic

#1 wwfc_barmy_army

wwfc_barmy_army
  • Members
  • PipPipPip
  • Advanced Member
  • 320 posts

Posted 16 September 2006 - 02:17 PM

Hello.

I'm reasonably new to PHP, and not sure how to do this IF statement, i need something like this:
<?php if ("$qry[editorrating] = 25") {
	echo "<img src='images/25.png'>";
	}
	if ("$qry[editorrating] = 05") {
	echo "<img src='images/05.png'>";
	}
	if ("$qry[editorrating] = 1") {
	echo "<img src='images/1.png'>";
	}
?>

But this doesn't work and just dispays all the images, what do i need to change so it just displays one of the images depending on what is in the database?

Thanks.

Peter.


#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 16 September 2006 - 02:19 PM

= is the assignment operator, == is the equality operator, so your tests should all be

if this == that not if this = that


... and if the information in the database is a string (which I hope it is, otherwise 05 is going to be 5):

if ($qry[editorrating] == "25")
Legend has it that reading the manual never killed anyone.
My site

#3 wwfc_barmy_army

wwfc_barmy_army
  • Members
  • PipPipPip
  • Advanced Member
  • 320 posts

Posted 16 September 2006 - 02:31 PM

Thanks. I currently have this code:
<?php if ($qry[editorrating] == "25") {
	echo "<img src='images/25.png'>";
	}
	if ($qry[editorrating] == "05") {
	echo "<img src='images/05.png'>";
	}
	if ($qry[editorrating] == "1") {
	echo "<img src='images/1.png'>";
	}
	?>

But i am getting this error (although the correct image is being displayed):

Notice: Use of undefined constant editorrating - assumed 'editorrating' in C:\public_html\RPG\site.php on line 54

Notice: Use of undefined constant editorrating - assumed 'editorrating' in C:\public_html\RPG\site.php on line 57

Notice: Use of undefined constant editorrating - assumed 'editorrating' in C:\public_html\RPG\site.php on line 60


Any ideas?

Thanks.

Peter.

#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 16 September 2006 - 02:47 PM

Any ideas? Yes! I should have had more coffee before replying.

The right syntax ought to be if ($qry['editorrating'] == "
Legend has it that reading the manual never killed anyone.
My site

#5 wwfc_barmy_army

wwfc_barmy_army
  • Members
  • PipPipPip
  • Advanced Member
  • 320 posts

Posted 16 September 2006 - 02:50 PM

;D Thanks!

#6 pkSML

pkSML
  • Members
  • PipPipPip
  • Advanced Member
  • 191 posts
  • LocationBucyrus, Ohio

Posted 16 September 2006 - 05:11 PM

If you ever get plagued by PHP error notices, you can disable them on the first line of your script by inserting this code.
error_reporting(E_ERROR | E_WARNING | E_PARSE);

Notices are not fatal, just for information, and can be annoying.

More info at http://us3.php.net/m...r-reporting.php.
-Stephen

Need a LitlURL?

Got code to share? --> The Code-Bin




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users