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 Link to comment https://forums.phpfreaks.com/topic/111316-solved-whats-wrong-here/ 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. Link to comment https://forums.phpfreaks.com/topic/111316-solved-whats-wrong-here/#findComment-571430 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. Link to comment https://forums.phpfreaks.com/topic/111316-solved-whats-wrong-here/#findComment-571431 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; } Link to comment https://forums.phpfreaks.com/topic/111316-solved-whats-wrong-here/#findComment-571433 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; } Link to comment https://forums.phpfreaks.com/topic/111316-solved-whats-wrong-here/#findComment-571436 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 />'; } ?> Link to comment https://forums.phpfreaks.com/topic/111316-solved-whats-wrong-here/#findComment-571438 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 Link to comment https://forums.phpfreaks.com/topic/111316-solved-whats-wrong-here/#findComment-571439 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?! Link to comment https://forums.phpfreaks.com/topic/111316-solved-whats-wrong-here/#findComment-571440 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 Link to comment https://forums.phpfreaks.com/topic/111316-solved-whats-wrong-here/#findComment-571442 Share on other sites More sharing options...
thebadbad Posted June 22, 2008 Share Posted June 22, 2008 Good Link to comment https://forums.phpfreaks.com/topic/111316-solved-whats-wrong-here/#findComment-571444 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.