If the items in <select> drop down menu are populated from mysql DB, like:

<?
echo "<select name=ptype>";
echo "<option value=\"\">------Select------</option>";
	for ($i = 0; $i < mssql_num_rows( $result0 ); ++$i)
	 {
	 $line = mssql_fetch_row($result0);
	 echo "<option value=$line[0]>$line[1]</option>";
              }
echo "</select>";
?>

Now I want to submit this form and if I want to pass another hidden data for each <select> item, I tried to use:

echo "<option value=$line[0]>$line[1]</option>";
echo "<input type=hidden name=a[$i] value=$line[2]>";
}

However it seems to add hidden value inside <select> loop will not work, I don't want to concatenate hidden value "$line[2]" to the option value "$line[0]", how can I pass the hidden values?

Thanks for any advice.

I didn't quite follow your question. You say you're having trouble "passing hidden values", but the code you've shown is for creating hidden input elements.

You'd simply do that in another, separate, loop.

What I mean is within <select> dropdown menu, I need to submit:
(1) <option value=$line[0]>
(2) another hidden value "$line[1]"
so after submitting the form, I can retrieve both option value and hidden value, for example the dropdown menu contains:
<option value=1> <input type=hidden name=a[1] value=first>
<option value=2> <input type=hidden name=a[2] value=second>

My question is how to "embed" hidden value inside <select> dropdown menu, so when I select "1" and submit, it submits both "1" and "first".

You will either have to 1) do another database request when processing the form to get your values or 2) use some javascript to grab the select value then add the hidden value to submit the form.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.