wwfc_barmy_army Posted September 24, 2006 Share Posted September 24, 2006 Hello.I'm reasonably new to php so i'm still a bit of a noob :PAnyways, i have a number of print commands displaying entrys from a database, although i am having trouble getting the following to work:[code]print "<td> if ($qry[editorrating] == 0) { echo '<img src='images/0.png'>'; } if ($qry[editorrating] == 12) { echo '<img src='images/05.png'>'; } if ($qry[editorrating] == 1) { echo '<img src='images/1.png'>'; } if ($qry[editorrating] == 15) { echo '<img src='images/15.png'>'; } if ($qry[editorrating] == 2) { echo '<img src='images/2.png'>'; } if ($qry[editorrating] == 25) { echo '<img src='images/25.png'>'; } if ($qry[editorrating] == 3) { echo '<img src='images/3.png'>'; } if ($qry[editorrating] == 35) { echo '<img src='images/35.png'>'; } if ($qry[editorrating] == 4) { echo '<img src='images/4.png'>'; } if ($qry[editorrating] == 45) { echo '<img src='images/45.png'>'; } if ($qry[editorrating] == 5) { echo '<img src='images/5.png'>'; }</td>";[/code]At the moment, i just get an error, i guess the print parts messing it up as it works on it's own on a different bit of my site. How can i make it so it works?Thanks!Peter. Quote Link to comment https://forums.phpfreaks.com/topic/21859-solvedprint-php/ Share on other sites More sharing options...
SharkBait Posted September 24, 2006 Share Posted September 24, 2006 Try this:[code]<?phpswitch ($qry['editorrating']) { case 0: $image = "0.png"; break; case 2: $image = "1.png"; break; case 2: $image = "2.png"; break; case 3: $image = "3.png"; break; case 12: $image = "05.png"; break; case 15: $image = "15.png"; break; case 25: $image = "25.png"; break; case 25: $image = "25.png"; break;}echo "<td><img src=\"images/{$image}\" /></td>";?>[/code]Echo and Print are pretty much the same thing, I used to use print, but then I started using echo instead...The switch() function is used for multiple if...else statements.Hope that helps... Quote Link to comment https://forums.phpfreaks.com/topic/21859-solvedprint-php/#findComment-97618 Share on other sites More sharing options...
kenrbnsn Posted September 24, 2006 Share Posted September 24, 2006 In this situation, I wouldn't even use a switch statement, since the number in the "editorrating" field is the same as the name part of the file. Try something like this:[code]<?phpif (file_exists($qry['editorrating'] . '.png')) echo '<td><img src="images/' . $qry['editorrating'] . '.png" /></td>';?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/21859-solvedprint-php/#findComment-97624 Share on other sites More sharing options...
Daniel0 Posted September 24, 2006 Share Posted September 24, 2006 It would have to be [code]<?phpif (file_exists('images/' . $qry['editorrating'] . '.png')) echo '<td><img src="images/' . $qry['editorrating'] . '.png" /></td>';?>since the image is located in the images folder ;)[/code] Quote Link to comment https://forums.phpfreaks.com/topic/21859-solvedprint-php/#findComment-97671 Share on other sites More sharing options...
wwfc_barmy_army Posted September 24, 2006 Author Share Posted September 24, 2006 Thanks Guys :)Pete. Quote Link to comment https://forums.phpfreaks.com/topic/21859-solvedprint-php/#findComment-97732 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.