Jump to content

[SOLVED] whats wrong here


serverman

Recommended Posts

here is the whole thing and yeah i is 1-5 never lands on 0... 0 means an error here is more of the script

$i = $r['cat_id'];
  switch ($i) 
  {
case 0:
   echo "nothing<br>";
   break;
case 1:
   echo '<img src="../img/php.gif" alt="" ><br>';
   break;
case 2:
   echo '<img src="../img/asp.gif" alt="" ><br>';
   break;
case 3:
   echo '<img src="../img/sql.gif" alt="" ><br>';
   break;
case 4:
   echo '<img src="../img/java.gif" alt="" ><br>';
   break;
case 5:
   echo '<img src="../img/html.gif" alt="" ><br>';
   break;	}

Link to comment
Share on other sites

i dont know why but this fixed it

 {
case 0:
    echo "nothing<br>";
    break;
case 1:
  ?><img src="../img/php.gif" alt="" ><br><?php
    break;
case 2:
?><img src="../img/asp.gif" alt="" ><br><?php
    break;
case 3:
  ?><img src="../img/sql.gif" alt="" ><br><?Php
    break;
case 4:
  ?><img src="../img/java.gif" alt="" ><br><?php 
    break;
case 5:
   ?><img src="../img/html.gif" alt="" ><?php
    break;	}

Link to comment
Share on other sites

Can't see anything wrong with it. And you're sure that the image path is right? I ask again: What is the output of the script (HTML source)? And the obvious question: Have you check that $i is not empty?? Your code is pretty repetitive. You can try:

 

<?php
$i = $r['cat_id'];
$cats = array('php', 'asp', 'sql', 'java', 'html');
if ($i > 0 && $i < 6) {
echo '<img src="../img/', $cats[$i - 1], '.gif" alt="" /><br />';
} elseif ($i == 0) {
echo 'nothing<br />';
}
?>

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.