Jump to content

SELECT/MENU List in with PHP


payney

Recommended Posts

Hi guys

 

I have a variable with a value of either y or n. Now, I need my select list to default to this value depending on what it is. I am not sure how to do this.

 

<?php

    $select = 'y';

?>

 

  <select name="select">

            <option value="y" selected>Yes</option>

            <option value="n">No</option>

          </select>

 

Thanks all!

Link to comment
Share on other sites

 

<?php
    $select = 'y';
?>

  <select name="select">
            <option value="y" <? if($select=="y") echo "selected"; ?>>Yes</option>
            <option value="n" <? if($select=="n") echo "selected"; ?>>No</option>
          </select> 

Link to comment
Share on other sites

<p>Display News: <? echo $row['display']; ?>

 

        <select name="display">

            <option value="y" <? if($row["display"]=="y") echo "display"; ?>>Yes</option>

            <option value="n" <? if($row["display"]=="n") echo "display"; ?>>No</option>

          </select>

 

 

Now, it works and gets the variable, but it dosnt set it to that value.

Link to comment
Share on other sites

Thanks, here it is.

 

//First I have the query

 

$query = "SELECT * FROM news_page WHERE pk= $pk";

$row = mysql_fetch_array($result);

 

//Then my form

 

  <select name="display">

            <option value="y" <? if($row["display"]=='y') echo "y"; ?>>Yes</option>

            <option value="n" <? if($row["display"]=='n') echo "n"; ?>>No</option>

          </select>

 

Basically, when I enter the page, the value is always set to yes. Does that make any sense?

 

 

Link to comment
Share on other sites

WHY ARE YOU COMPLETELY IGNORING THE HTML TO GET AN OPTION SELECTED????

 

<select name="display">

<option value="y" <? if($row["display"]=='y') echo ' selected="selected"'; ?>>Yes</option>

<option value="n" <? if($row["display"]=='n') echo ' selected="selected"': ?>>No</option>

</select>

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.