|
Posted by MattMika on 10/25/05 21:20
I have a script that I need some direction with.This is pulling sizes
available for a particular garment(selected earlier in the form) and
creating a textfield for quantity for each size found.
Heres a snippet of code:
<!---////////////////////////////////////////////////////// JERSEY
SIZE QUANTITIES
//////////////////////////////////////////////////////---><?
if ($_POST["jerseystyles"]){
echo "<tr><td align=\"left\"><b>Jersey Sizes:</b></td>";
$query = "SELECT products.product_id, products.product_name,
products_options.option_name, products_options.product_id
FROM products, products_options
WHERE products_options.product_id=products.product_id AND
products.product_name='$_POST[jerseystyles]' AND
products_options.option_type='2'";
$jerseyresult=mysql_query($query) or die(mysql_error());
// PROCESS QUERY RESULTS INTO COLUMNS/TABLES
$columns=6;
$jerseysize=array();
$jerseysizeid=array();
// CALCULATE ROWS
$rows=ceil(mysql_num_rows($jerseyresult)/$columns);
for ($x = 1; $x <= $columns; $x++) {
for ($y =1; $y <= $rows; $y++)
$jerseysize[$x][$y]=mysql_fetch_array($jerseyresult);
}
echo "<td align=\"left\"><table><tr>";
// COLUMN WISE DYNAMIC TABLE
for ($y =1; $y <= $rows; $y++) {
echo "<tr>";
for ($x = 1; $x <= $columns; $x++)
if (isset($jerseysize[$x][$y]['option_name'])) {
array_push($jerseysizeid,
$jerseysize[$x][$y]['option_name']);
echo "<td
align=\"center\"><b>".$jerseysize[$x][$y]['option_name']. "</b>" . "
<input class=8pt type=\"text\" size=\"1\" maxlength=\"3\"
name=\"jerseysizeform[]\"\"></td>";
}else{
echo "<td></td>";
echo "</tr>\n";
}
}
echo "</tr><tr><td class=\"alert\" colspan=\"6\">Enter quantities for
each jersey size you wish to order.</td></tr></table></td></tr>";
// ELIMINATE ERRORS IF ARRAY IS EMPTY
if (isset($jerseysizeform)){
$jerseysizeform=@$_POST["jerseysizeform"];
sort($jerseysizeform);
} else {
$jerseysizeform=array();
}
// DISPLAY
foreach($jerseysizeform as $key => $jerseyqty) {
echo "$jerseyqty";
}
echo "<br>";
foreach($jerseysizeid as $key => $jerseysizes){
echo "$jerseysizes";
}
}
?>
I can get the quantities entered into the text fields
fine($jerseysizeform) and I can fill an array with the actual
sizes($jeseysizeid), ie. YS, YM, YL, etc. How can I use these arrays
together to insert YS-6, YM-5, YL-4, and so on?
The table structure is:
team_id
product_id
size
qty
So I need to loop inserts for each size populated in the form and the
quantities entered by the user.
Im still a bit green and could use some suggestions on how best to
accomplish this. Hopefully I explained sufficiently.
TIA
Matt Mika
Navigation:
[Reply to this message]
|