0

I have a parent table and a child table linked with an Id. The child table has two fields - ch_id and item. The parent table has a field which stores the value of ch_id for that row. I have set up a php script to generate a selection list in an html page.
The selection list only displays the text values of 'item'. Following a Submit the $_POST value will contain the text of the selected item. However, I want to store the ch_id value corresponding.
A couple of ways that I can see, that I do not like, are - display the ch_id and the item text in the selection list and strip the id out before storing. This looks messy on the form; or do a reverse mySQL selection before updating the parent table.
Is there a smarter way to achieve this? In MS Access the list box can contain both fields with the id not displaying but being linked to the parent field.

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by GeoffC
0

I believe there's a way for you to not display the ch_id on the form anymore while querying the database but directly assign it to a different variable ready for storage. You might find using <input type="hidden"> helpful in some cases.

If you can show us a sample of your code that would be great.

0

//get Branch data
$get_list = "SELECT * FROM drop_downs WHERE type = '2' ORDER BY text";
$get_list_branch = mysql_query($get_list) or die(mysql_error());

<td><select name="branch">
<option></option>
<?php
while ($recs_branch = mysql_fetch_array($get_list_branch))
{
echo '<option ' . (($recs_branch[dd_id] == $recs[branch]) ? "selected=selected" : "") . '>' . $recs_branch[dd_id] . " " . $recs_branch[text] . '&nbsp;&nbsp;&nbsp;</option>';
}
?>
</select>
</td>

0

You need a value attribute linked to DB id in each option.

<option value = "3">text for id3</option>

$_POST will then return the value of the selected option after form submit.

0

Thanks Ardav - when I look at the documentation, that is the obvious solution.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.