Jump to content


Photo

PHP Form Help


  • Please log in to reply
4 replies to this topic

#1 embsupafly

embsupafly
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 07 April 2006 - 05:11 PM

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:

$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>";
}

Eric

#2 craygo

craygo
  • Staff Alumni
  • Advanced Member
  • 1,973 posts
  • LocationRhode Island

Posted 07 April 2006 - 08:20 PM

You could just add a hidden form value between your form tags

<input type=hidden name=price value=$price>

Ray

#3 embsupafly

embsupafly
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 07 April 2006 - 08:43 PM

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.
Eric

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 07 April 2006 - 09:13 PM

You could add the price to the value in the "<option></option>" block:
<?php
$parts_block .= "<option value='$part_number/$price'>$part_number: $description ($vendor) \$$price</option>";
?>
And then in your script use the explode() function to split the part_number from the price.

Ken

#5 embsupafly

embsupafly
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 07 April 2006 - 10:27 PM

[!--quoteo(post=362658:date=Apr 7 2006, 09:13 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Apr 7 2006, 09:13 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
You could add the price to the value in the "<option></option>" block:
<?php
$parts_block .= "<option value='$part_number/$price'>$part_number: $description ($vendor) \$$price</option>";
?>
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.

Eric




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users