Jump to content

For Each Statements


Xtremer360

Recommended Posts

Anything wrong with this because I got a parse error ONLY after adding to create this.

 

<?php
                            $visible = array('Yes', 'No');
                            foreach($visible as $visible):
                            $visible2 = array('yes', 'no');
                            foreach($visible2 as $visible2):
                        ?>      

Link to comment
Share on other sites

Here's the whole select tag. The idea is to have the value of the options be yes and no but for it to show Yes and No to the user to select either.

 

<select name="visible" class="dropdown">
                        <option value="0">- Select -</option>
                        <?php
                            $visible = array('Yes', 'No');
                            foreach($visible as $visible):
                            $visible2 = array('yes', 'no');
                            foreach($visible2 as $visible2):
                        ?>        
                            <option value="<?php echo $visible2; ?>"<?php if($visible == $row['visible']): echo ' SELECTED'; endif; ?>><?php echo $visible; ?></option>
                         
                         <?php endforeach; ?>
                        </select>

Link to comment
Share on other sites

$options = array(
    // option_val => display_text
    "yes" => "Yes",
    "no" => "No"
);
foreach($options as $key => $val) {
    echo "<option value=\"".$key."\"";
    if($key == $row['visible']) echo " selected=\"selected\"";
    echo ">".$val."</option>\n";
}

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.