Jump to content

[SOLVED] if inside an echo


anth0ny

Recommended Posts

How would i write this:

 

<?php if ( $stars == '5' ) {
$stars = "";
echo '<img src="../../elements/images/layout/5star.jpg" alt="5 star"/>';
}


if ( $stars == '4' ) {
$stars = "";
echo '<img src="../../elements/images/layout/4star.jpg" alt="4 star"/>';
}

if ( $stars == '3' ) {
$stars = "";
echo '<img src="../../elements/images/layout/3star.jpg" alt="3 star"/>';
}

if ( $stars == '2' ) {
$stars = "";
echo '<img src="../../elements/images/layout/2star.jpg" alt="2 star"/>';
}

if ( $stars == '1' ) {
$stars = "";
echo '<img src="../../elements/images/layout/1star.jpg" alt="1 star"/>';
}

if ( $stars == '0' ) {
$stars = "";
echo '<img src="../../elements/images/layout/0star.jpg" alt="0 star"/>';
}

echo $stars;?>

 

inside this:

 

<?php <li class=\"med\">  TO GO HERE?  </li> ?>

Link to comment
Share on other sites

<li class="med">
<?php 
switch($stars) {
case '5':
   echo '<img src="../../elements/images/layout/5star.jpg" alt="5 star"/>';
   break;
case '4':
   echo '<img src="../../elements/images/layout/4star.jpg" alt="4 star"/>';
   break;
//etc
   default:
   die("Invalid result");
   break;
} 
$stars = "";
?>
</li>

Link to comment
Share on other sites

-or just echo the open LI before the IFs and the close LI after the IFs

-or put the LIs inside each IF

 

I like this way:

<?php
  echo '<li class="">'; 
  switch($star){
    case 5:
      echo '<img src="../../elements/images/layout/4star.jpg" alt="4 star"/>';
      break;
    case 4:
      echo '<img src="../../elements/images/layout/4star.jpg" alt="4 star"/>';
      break;
    case 3:
      echo '<img src="../../elements/images/layout/3star.jpg" alt="3 star"/>';
      break;
    case 2:
      echo '<img src="../../elements/images/layout/2star.jpg" alt="2 star"/>';
      break;
    case 1:
      echo '<img src="../../elements/images/layout/1star.jpg" alt="1 star"/>';
      break;
    case 0:
      echo '<img src="../../elements/images/layout/0star.jpg" alt="0 star"/>';
      break;
  }
  echo '</li>';
?>

or this way:

<?php
  echo "<li class=\"\"><img src=\"../../elements/images/layout/{$star}star.jpg\" alt=\"{$star} star\"/></li>";
?>

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.