embsupafly Posted April 7, 2006 Share Posted April 7, 2006 OK, Here is what I am doing. I am creating a table with 10 rows that will have 10 select fields and 10 text boxes. The 10 select fields are generated by a SQL query to pull all of the parts from a table and show the Part Number, Description, Vendor, and Price. This is for an invoice so this allows for the selection of up to 10 parts for the invoice and for each part you enter the quantity in its associated text box. For the select name that is passed off to the next script, I have it passing the part number so I can identify what part it is that they chose, but I also want the price to go along with it, but the price is only in the dropdown description area. I want the price to pass with the product, because I want its current price recorded on the invoice, rather than query the database at a later time to get the price for that product, just in case the product price is updated. This is what I have for the piece of the table in the form:[code]$sql_parts_select = "SELECT * FROM $parts_table";$parts_block = "<option value=''>-- Select Part --</option>";$result_parts = @mysql_query($sql_parts_select,$connection) or die(mysql_error());while ($row = mysql_fetch_array($result_parts)) {$vendor = $row['vendor'];$part_number = $row['part_number'];$description = $row['description'];$price = $row['price'];$parts_block .= "<option value=\"$part_number\">$part_number: $description ($vendor) \$$price</option>";$table_rows = "";for ($i=1;$i<=10;$i++) {$table_rows .= " <tr> <td width=\"80%\" class=\"form\"><select name=\"pc[]\">$parts_block</select></td> <td width=\"20%\" class=\"form\"><input type=\"text\" name=\"qpc[]\" size=\"2\"></td> </tr>";}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/6822-php-form-help/ Share on other sites More sharing options...
craygo Posted April 7, 2006 Share Posted April 7, 2006 You could just add a hidden form value between your form tags[code]<input type=hidden name=price value=$price>[/code]Ray Quote Link to comment https://forums.phpfreaks.com/topic/6822-php-form-help/#findComment-24872 Share on other sites More sharing options...
embsupafly Posted April 7, 2006 Author Share Posted April 7, 2006 No because each of the 10 drop downs are going to have different items with different prices, so there needs to be a way to keep the price tied to the individual item. Quote Link to comment https://forums.phpfreaks.com/topic/6822-php-form-help/#findComment-24879 Share on other sites More sharing options...
kenrbnsn Posted April 7, 2006 Share Posted April 7, 2006 You could add the price to the value in the "<option></option>" block:[code]<?php$parts_block .= "<option value='$part_number/$price'>$part_number: $description ($vendor) \$$price</option>";?>[/code]And then in your script use the explode() function to split the part_number from the price.Ken Quote Link to comment https://forums.phpfreaks.com/topic/6822-php-form-help/#findComment-24885 Share on other sites More sharing options...
embsupafly Posted April 7, 2006 Author Share Posted April 7, 2006 [!--quoteo(post=362658:date=Apr 7 2006, 09:13 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Apr 7 2006, 09:13 PM) [snapback]362658[/snapback][/div][div class=\'quotemain\'][!--quotec--]You could add the price to the value in the "<option></option>" block:[code]<?php$parts_block .= "<option value='$part_number/$price'>$part_number: $description ($vendor) \$$price</option>";?>[/code]And then in your script use the explode() function to split the part_number from the price.Ken[/quote]Perfect Ken, just the type of thing I was looking for. Never thought to combine then explode them, but its a very simple concept. Sometimes I overlook the simple things. Quote Link to comment https://forums.phpfreaks.com/topic/6822-php-form-help/#findComment-24901 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.