Jump to content

[Solved]Print PHP


wwfc_barmy_army

Recommended Posts

Hello.

I'm reasonably new to php so i'm still a bit of a noob :P

Anyways, 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.
Link to comment
https://forums.phpfreaks.com/topic/21859-solvedprint-php/
Share on other sites

Try this:

[code]
<?php

switch ($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...

Link to comment
https://forums.phpfreaks.com/topic/21859-solvedprint-php/#findComment-97618
Share on other sites

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]<?php
if (file_exists($qry['editorrating'] . '.png')) echo '<td><img src="images/' . $qry['editorrating'] . '.png" /></td>';
?>[/code]

Ken
Link to comment
https://forums.phpfreaks.com/topic/21859-solvedprint-php/#findComment-97624
Share on other sites

Archived

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

×
×
  • 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.