List menu Help?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
rayfusion
Forum Newbie
Posts: 3
Joined: Fri Jul 05, 2002 10:00 pm

List menu Help?

Post by rayfusion »

I am pulling a record into a form so I could modify that record. One of the fields in the form is a List Menu. I want to pull the value of the List Menu for that record as the selected value. I also want to have all of the other options in the List Menu available for me to choose if needed. Thanks in advance.

::rayfusion---> t = everlasting life ::
ajaypatil
Forum Newbie
Posts: 17
Joined: Wed Jul 03, 2002 2:15 am
Location: Pune, India
Contact:

Post by ajaypatil »

What have you tried so far ?

Ajay
rayfusion
Forum Newbie
Posts: 3
Joined: Fri Jul 05, 2002 10:00 pm

Post by rayfusion »

Here is the code so far....

<select name="tech_group" id="tech_group" title="<?php echo $row_rsChoose_Tech_Group['tech_group']; ?>">
<?php
do {
?>
<option value="<?php echo $row_rs_modify['tech_group']?>"<?php if (!(strcmp($row_rs_modify['tech_group'], $row_rs_modify['tech_group']))) {echo "SELECTED";} ?>><?php echo $row_rs_modify['tech_group']?></option>
<?php
} while ($row_rs_modify = mysql_fetch_assoc($rs_modify));
$rows = mysql_num_rows($rs_modify);
if($rows > 0) {
mysql_data_seek($rs_modify, 0);
$row_rs_modify = mysql_fetch_assoc($rs_modify);
}
?>
</select>
ajaypatil
Forum Newbie
Posts: 17
Joined: Wed Jul 03, 2002 2:15 am
Location: Pune, India
Contact:

Post by ajaypatil »

Hi,

You seem to be proceeding in right direction.
I have the following suggestions:
a) The names $rs_modify and $row_rs_modify are very confusing.
Is this the list of all records in tech group table.
If yes, then $rs_tech_group is more meaningful.

b) As I understand, you want to show the current value in form
as selected in the list menu.
If so, then you should read the current value in form into a
variable like $current_tech_group and then compare against
each value in the list menu.

Your code

Code: Select all

<option value="<?php echo $row_rs_modify&#1111;'tech_group']?>"<?php if (!(strcmp($row_rs_modify&#1111;'tech_group'], $row_rs_modify&#1111;'tech_group']))) &#123;echo "SELECTED";&#125; ?>><?php echo $row_rs_modify&#1111;'tech_group']?></option>
should be something like:

Code: Select all

<option value="<?php echo $row_rs_modify&#1111;'tech_group']?>"
  <?php if ($row_rs_modify&#1111;'tech_group'] == $current_tech_group) 
            &#123;echo "SELECTED";&#125; ?>
><?php echo $row_rs_modify&#1111;'tech_group']?></option>
If you still have some problems, please paste your entire code
including the queries to select the form record and the list menu values.

Ajay
Post Reply