Jump to content

Recommended Posts

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;

?>

Link to comment
https://forums.phpfreaks.com/topic/202057-else-if-statment-breaking/
Share on other sites

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

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']];?>

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

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.