Jump to content

PHP Form Help


embsupafly

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.