liamloveslearning Posted May 17, 2010 Share Posted May 17, 2010 Hi everyone, this code keeps breaking my page, Can I pick anybodies brains to see if they can see the error? <?php if(@$row_getdets['travelrad'] == 1): echo "locally"; elseif(@$row_getdets['travelrad'] == 2): echo "Anywhere in the UK"; elseif(@$row_getdets['travelrad'] == 3): echo "Worldwide"; else: endif; ?> Quote Link to comment https://forums.phpfreaks.com/topic/202057-else-if-statment-breaking/ Share on other sites More sharing options...
MadTechie Posted May 17, 2010 Share Posted May 17, 2010 Nothing (technically) wrong with the code Define: Breaks your page Quote Link to comment https://forums.phpfreaks.com/topic/202057-else-if-statment-breaking/#findComment-1059593 Share on other sites More sharing options...
liamloveslearning Posted May 17, 2010 Author Share Posted May 17, 2010 my page isnt being outputted, im seeing a white screen with no source Quote Link to comment https://forums.phpfreaks.com/topic/202057-else-if-statment-breaking/#findComment-1059604 Share on other sites More sharing options...
liamloveslearning Posted May 17, 2010 Author Share Posted May 17, 2010 And it cant be the rest of my code as im literally replacing <?php echo $row_getdets['travelrad']; ?> with the above Quote Link to comment https://forums.phpfreaks.com/topic/202057-else-if-statment-breaking/#findComment-1059606 Share on other sites More sharing options...
iblood Posted May 17, 2010 Share Posted May 17, 2010 your script must have fallen on the last else statement.. have you tied to echo sumthing on that last else statement? Quote Link to comment https://forums.phpfreaks.com/topic/202057-else-if-statment-breaking/#findComment-1059610 Share on other sites More sharing options...
kenrbnsn Posted May 17, 2010 Share Posted May 17, 2010 Your suppressing any errors by using the "@". Remove it while debugging. A better way of doing this (IMHO) would be: <?php $dest = array('','locally','anywhere in the UK','Worldwide'); if ($row_getdets['travelrad'] > 0 && $row_getdets['travelrad'] < 4) { echo $dest[$row_getdets['travelrad']]; } ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/202057-else-if-statment-breaking/#findComment-1059612 Share on other sites More sharing options...
liamloveslearning Posted May 17, 2010 Author Share Posted May 17, 2010 Thats amazing that kenrbnsn! worked perfectly! sorry to be a pain but could you explain how it works? Quote Link to comment https://forums.phpfreaks.com/topic/202057-else-if-statment-breaking/#findComment-1059736 Share on other sites More sharing options...
liamloveslearning Posted May 17, 2010 Author Share Posted May 17, 2010 Ive jsut tried altering it so I can use it on another variable I have and it isnt working, im unsure what the funtions called but does this seem valid? <?php $workcon = array('','Portrait','Catwalk','Glamour','Implied Topless','Implied Nude','Glamour Topless','Glamour Nude', 'Promotions','Other'); if ($row_getdets['workconsidered'] > 0 && $row_getdets['workconsidered'] < 10) { echo $workcon[$row_getdets['workconsidered']];?> Quote Link to comment https://forums.phpfreaks.com/topic/202057-else-if-statment-breaking/#findComment-1059740 Share on other sites More sharing options...
kenrbnsn Posted May 17, 2010 Share Posted May 17, 2010 The only problem I'm seeing in your code is that you don't close the "if" block with a "}". One change I would make to my original "if" would be to count($array) in the second condition: <?php if ($row_getdets['workconsidered'] > 0 && $row_getdets['workconsidered'] < count($workcon)) { echo $workcon[$row_getdets['workconsidered']]; } ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/202057-else-if-statment-breaking/#findComment-1059747 Share on other sites More sharing options...
liamloveslearning Posted May 17, 2010 Author Share Posted May 17, 2010 Thanks ken Quote Link to comment https://forums.phpfreaks.com/topic/202057-else-if-statment-breaking/#findComment-1059750 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.