Jump to content

Archived

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

wwfc_barmy_army

[Solved]Print PHP

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.

Share this post


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

Share this post


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

Share this post


Link to post
Share on other sites
It would have to be [code]<?php
if (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]

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.