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
https://forums.phpfreaks.com/topic/72439-selectmenu-list-in-with-php/
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.

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?

 

 

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.