Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

display multiple fields in dropdown 1

Status
Not open for further replies.

hovercraft

Technical User
Jun 19, 2006
236
US
Greetings,

I'm having a bit of a problem with the values in a dropdown.

I have 3 fields in a mysql table. I would like to display 2 of those fields as an <option> in a dropdown however, the 3rd field's value is what I wish to capture.

The fields are;
1) desc_descid
2) desc_desc_s
3) desc_desc_l

I'm trying to display fields 2 and 3 but actually capture the value of field 1 (desc_descid).

Here is what I have thus far
Code:
$rs_desc = mysql_query("SELECT * FROM `inv_desc` WHERE desc_descid > '0';"); 

echo '<p>'."Enter NEW Pallet Data".'<br>';
echo '<select name="my_descid">';

while ( $row = mysql_fetch_array($rs_desc) )
{
echo '<option>'.($row["desc_descid"]).'</option>';
}
echo '</select> </p>';

This of course displays the desc_descid but I can't figure out how "not to display" the value of desc_descid but allow the two other fields to be displayed in line as part of the option.

I hope I'm making sense.
Thank you very much in advance.
 
Values are returned from <OPTION> tags by setting the tag's "value" atribute:

<option value="somevalue">Some text to display</option>

values are not displayed.




Want the best answers? Ask the best questions! TANSTAAFL!
 
Awesome! Thank you sir.

This is what I end up with.

Code:
echo '<option value='.($row["desc_descid"]).'>'.($row["desc_desc_s"]).'---'.($row["desc_desc_l"]).'</option>';

:)
 
I strongly recommend that you put quotes around all attribute values. Instead of:

Code:
<option value=foo>bar</option>

do

Code:
<option value=[red]"[/red]foo[red]"[/red]>bar</option>


If you don't and the value has a space in it:

Code:
<option value=foo baz>bar</option>

then your browser will assume the value ends at the space.



Want the best answers? Ask the best questions! TANSTAAFL!
 
ah, good point.

so something like this?

Code:
echo '<option value="'.($row["desc_descid"]).'">'.($row["desc_desc_s"]).'---'.($row["desc_desc_l"]).'</option>';
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top