Jump to content

[SOLVED] Listmenu value to variable


biggieuk

Recommended Posts

Hi,

 

Im having trouble assigning the value of a listmenu item to a variable.

 

the listmenu is populated dynamically from a database using 'username' as the label and 'email' as the value.

 

I need to assign the 'email' value of the selected item to a variable.

 

Can anybody please give me some guidance.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/106159-solved-listmenu-value-to-variable/
Share on other sites

Your not going to like it, i used Dreamweaver to dynamically populate the listmenu  ::)

 

<select name="select2" id="select2" disabled = "disabled">
    <?php
do {  
?>
    <option value="<?php echo $row_users['email']?>"<?php if (!(strcmp($row_users['email'], $row_users['email']))) {echo "selected=\"selected\"";} ?>><?php echo $row_users['username']?></option>
    <?php
} while ($row_users = mysql_fetch_assoc($users));
  $rows = mysql_num_rows($users);
  if($rows > 0) {
      mysql_data_seek($users, 0);
  $row_users = mysql_fetch_assoc($users);
  }
?>
  </select>

Obviously your axpecting more than one email? If so, you'll need to store them in an array. eg;

 

<?php
do {  
?>
    <option value="<?php echo $row_users['email']?>"<?php if (!(strcmp($row_users['email'], $row_users['email']))) {echo "selected=\"selected\"";} ?>><?php echo $row_users['username']?></option>
    <?php
} while ($row_users = mysql_fetch_assoc($users));
  $rows = mysql_num_rows($users);
  if($rows > 0) {
      mysql_data_seek($users, 0);
      $row_users = mysql_fetch_assoc($users);
      $emails[] = $row_users['email'];
  }
?>

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.