Jump to content


Photo

[Solved]Print PHP


  • Please log in to reply
4 replies to this topic

#1 wwfc_barmy_army

wwfc_barmy_army
  • Members
  • PipPipPip
  • Advanced Member
  • 320 posts

Posted 24 September 2006 - 11:59 AM

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:
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>";

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.

#2 SharkBait

SharkBait
  • Members
  • PipPipPip
  • Advanced Member
  • 845 posts
  • LocationMetro Vancouver, BC

Posted 24 September 2006 - 12:12 PM

Try this:

<?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>";

?>

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



#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 24 September 2006 - 12:48 PM

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

Ken

#4 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 24 September 2006 - 06:28 PM

It would have to be
<?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 ;)


#5 wwfc_barmy_army

wwfc_barmy_army
  • Members
  • PipPipPip
  • Advanced Member
  • 320 posts

Posted 24 September 2006 - 08:08 PM

Thanks Guys :)

Pete.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users