Jump to content

Archived

This topic is now archived and is closed to further replies.

embsupafly

PHP Form Help

Recommended Posts

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]

Share this post


Link to post
Share on other sites
You could just add a hidden form value between your form tags

[code]<input type=hidden name=price value=$price>[/code]

Ray

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
[!--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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.