Page 1 of 1
get the matching id of the selected item in the listbox
Posted: Tue Sep 09, 2008 9:14 am
by zplits
Hi there, good day to all. Does any know how to get the matching id of the selected item in the listbox?
If you don't know what i mean, here is a screenshot below. To help you to better understand what is my prob. The screenshot below show the supplies page, it is here that i enter and save data into the database.
And in the image below, the saved items in the supplies page will be use here,
My problem:
I have only 1 problem and that is to get the code for the selected description in the drop-down list box. For example i choose cheese in the description field, and fill up other info, then when i press the save button, the data will be saved in the database and be displayed in the table below. Because i have chosen cheese the code that will appear in the table will be "1211". Because in the supplies page, cheese has the code of 1211.
Any help? Thanks in advance.
Re: get the matching id of the selected item in the listbox
Posted: Tue Sep 09, 2008 10:35 am
by yacahuma
your description should already have the value
Code: Select all
<select name="description">
<option value="1211">Cheese</option>
<option value="0019">Milk</option>
<option value="0007">Onion</option>
</select>
Re: get the matching id of the selected item in the listbox
Posted: Tue Sep 09, 2008 10:40 am
by zplits
thanks for the response sir, Here is the code for the select box
Code: Select all
<?php
$querySupplies = "SELECT supplies_PK, code, name, quantity, measurement, perUnitCost, totalCost FROM $tbl_name2";
$resultSupplies = mysql_query($querySupplies,$connection);
$getResultSupplies = $resultSupplies;
echo "<select name=\"description\" size=\"1\" class=\"formFieldsDropDownCode\" id=\"code\" tabindex=\"4\">";
while($row = mysql_fetch_assoc($getResultSupplies)){
$showName=$row['name'];
echo "<option value=".$showName.">".$showName."</option>";
}
//echo "<input type=\"hidden\" name=\"code\" id=\"hiddenField\" value=".$code."/>";
echo "</select>";
?>
I want to match the selected item with it's corresponding code no. Please help me out.
Re: get the matching id of the selected item in the listbox
Posted: Tue Sep 09, 2008 12:05 pm
by yacahuma
Code: Select all
while($row = mysql_fetch_assoc($getResultSupplies)){
$showName=$row['name'];
$code=$row['code'];
echo "<option value=".$code.">".$showName."</option>";
}
Re: get the matching id of the selected item in the listbox
Posted: Tue Sep 09, 2008 9:38 pm
by zplits
Thanks...I have made what you have advised, it's successful, but one more thing, the i can't save the selected description in the database.
This is the code:
Code: Select all
while($row = mysql_fetch_assoc($getResultSupplies)){
$showName=$row['name'];
$code=$row['code'];
[b][color=#BF0000]echo "<option value=".$code.">".$showName."</option>"[/color][/b];
}
take note of the bolded line of code, the value is $code, how can i also get the value of $showName and save it in the database?
Re: get the matching id of the selected item in the listbox
Posted: Wed Sep 10, 2008 5:06 am
by yacahuma
you are not supposed to . Thats how relational tables work. to get the description you join the tables
http://www.w3schools.com/Sql/sql_join.asp
Re: get the matching id of the selected item in the listbox
Posted: Wed Sep 10, 2008 5:11 am
by onion2k
Mmm.. Kraft Cheese.

Re: get the matching id of the selected item in the listbox
Posted: Wed Sep 10, 2008 7:10 am
by Stryks
I still don't get the table (for the purposes of this post, 'table' means the grid you are displaying the data in, not a database table) you are using to display the information.
I mean, I might be missing something, but you're carrying the quantity and cost values though three stages per row. What happens if the price changes? What about days where there are no purchases? What happens if you change supplier or manufacturer - Two rows for one product?
And having the date column makes no sense to me for listing all items. If you have 20 different items, you're going to have 20 rows of data, per day ... apparently for as many days as you have stored. This is not going to tell anyone anything at a glance.
I've tried to mention this to you once, but I'll try again. The data you are showing should, I believe, be in *at least* two separate tables. One without dates showing quantity on hand and total value (one row per product) and a second drill-down table showing the last, say 30 days of purchases and usages and the dates those changes occurred. This table might also show the price paid.
Anyhow, on topic, you store the ID and join in your SQL to pull the name. I know you don't really understand that, so you're going to have to go on faith a bit. It's just the way it's done.
Cheers