wwfc_barmy_army Posted September 16, 2006 Share Posted September 16, 2006 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. Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 16, 2006 Share Posted September 16, 2006 = 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") Quote Link to comment Share on other sites More sharing options...
wwfc_barmy_army Posted September 16, 2006 Author Share Posted September 16, 2006 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 54Notice: Use of undefined constant editorrating - assumed 'editorrating' in C:\public_html\RPG\site.php on line 57Notice: Use of undefined constant editorrating - assumed 'editorrating' in C:\public_html\RPG\site.php on line 60[/quote]Any ideas?Thanks.Peter. Quote Link to comment Share on other sites More sharing options...
AndyB Posted September 16, 2006 Share Posted September 16, 2006 Any ideas? Yes! I should have had more coffee before replying.The right syntax ought to be if ($qry['editorrating'] == " Quote Link to comment Share on other sites More sharing options...
wwfc_barmy_army Posted September 16, 2006 Author Share Posted September 16, 2006 ;D Thanks! Quote Link to comment Share on other sites More sharing options...
pkSML Posted September 16, 2006 Share Posted September 16, 2006 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]. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.