Jump to content

Archived

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

wwfc_barmy_army

[Solved]How would i do this if statement?

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.

Share this post


Link to post
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")

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
Any ideas? Yes! I should have had more coffee before replying.

The right syntax ought to be if ($qry['editorrating'] == "

Share this post


Link to post
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].

Share this post


Link to post
Share on other sites

×

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.