Jump to content

[Solved]How would i do this if statement?


wwfc_barmy_army

Recommended Posts

Hello.

I'm reasonably new to PHP, and not sure how to do this IF statement, i need something like 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'>";
}
?>[/code]

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.
Link to comment
Share on other sites

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

if [b]this == that[/b] 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")
Link to comment
Share on other sites

Thanks. I currently have this code:
[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'>";
}
?>[/code]

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

[quote]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[/quote]

Any ideas?

Thanks.

Peter.
Link to comment
Share on other sites

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

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

More info at [url=http://us3.php.net/manual/en/function.error-reporting.php]http://us3.php.net/manual/en/function.error-reporting.php[/url].
Link to comment
Share on other sites

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.