serverman Posted June 22, 2008 Share Posted June 22, 2008 <?php $i = $r['cat_id']; switch ($i) { case 0: echo "nothing<br>"; break; case 1: echo '<img src="../img/php.gif" alt="" align="right"><br>'; break; ?> why doesnt it show the picture ... the switch works fine Quote Link to comment Share on other sites More sharing options...
thebadbad Posted June 22, 2008 Share Posted June 22, 2008 What's the HTML source of the output, when $i is 1? Maybe the image path is wrong. Quote Link to comment Share on other sites More sharing options...
thebadbad Posted June 22, 2008 Share Posted June 22, 2008 Arh, you're missing a closing bracket for the switch block. Quote Link to comment Share on other sites More sharing options...
serverman Posted June 22, 2008 Author Share Posted June 22, 2008 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; } Quote Link to comment Share on other sites More sharing options...
serverman Posted June 22, 2008 Author Share Posted June 22, 2008 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; } Quote Link to comment Share on other sites More sharing options...
thebadbad Posted June 22, 2008 Share Posted June 22, 2008 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 />'; } ?> Quote Link to comment Share on other sites More sharing options...
serverman Posted June 22, 2008 Author Share Posted June 22, 2008 here it is http://67.235.135.133/tutorial/index.php working im not shure why it works now but it does it outputs the same thing without the change i made that fixed it but the pics didnt show up on firefox3 ... now im going to try your fix it looks cleaner and like it will run faster Quote Link to comment Share on other sites More sharing options...
thebadbad Posted June 22, 2008 Share Posted June 22, 2008 If it outputted the same thing, it would work if it does now.. weird?! Quote Link to comment Share on other sites More sharing options...
serverman Posted June 22, 2008 Author Share Posted June 22, 2008 i have no clue why it didn't display but both ways work but your way is cleaner so im using it Thank you it works like a charm Quote Link to comment Share on other sites More sharing options...
thebadbad Posted June 22, 2008 Share Posted June 22, 2008 Good Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.