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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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