PDA

View Full Version : need help with this array form please


mr_one1999
01-28-2005, 01:35 PM
hi all,

I have an old script which has a dynamically populated form where the
user chooses the items from as many list/menu as the categories
existing in the database and then on a confirm page only the items
selected are shown to be checked by the user before sending them ( to a
third script )

Now I would like to add another list/menu field in the form to let the
user choosing the quantity of each item selected, but I don't know how
to handle it in the confirm page . I use a "foreach" to display the
array of items in the next page
, but how can I show the quantity for each item too ?

I post the code of both pages below ( only the part of interest )

TIA

Johnny


FORM PAGE


<form name="form1" method="post" action="confirm.php">


<?php


$cat=mysql_query("SELECT DISTINCT category FROM table ORDER BY
id", $db);
while ($category=mysql_fetch_array($cat)) {
$array_categoy[]=$category["category"];

}

foreach($array_category as $key=>$val) {
$data_link=mysql_query("SELECT * FROM table WHERE
category='$val'",$db);
?>
<?php $label = str_replace ( "_"," ",$val) ; ?>
<p> <?php echo $label; ?></p>

// THE PART I WOULD LIKE TO ADD

<select name="quantity" id="quantity">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>

// END OF NEW PART
<select name="field[<?php $val ?>]"id="<?php $val ?>">
<option > - - - - - - - - - - - - </option>
<?php
while ($link=mysql_fetch_array($data_link)) {
$description_link= $link["product"];
$id_link = $link["id"];
$code_link = $link["code"];

print "<option value=\"$code_link = $description_link\">
$description_link </option>";

}

?>
</select>
<?php

}

?>

<input name="Submit" type="submit" value="GO ON >>">
</form>


CONFIRM PAGE


<form name="form1" method="post" action="send.php">
<p>Please check the data u entered</p>
<p>
<input name="hiddenField" type="hidden" value="<?php

foreach ($_POST['field'] as $name=>$value) {

// HOW TO ADD THE QUANTITY TOO ?

echo nl2br("$value");

}

?>">

<?php

foreach ($_POST['field'] as $name=>$value) {

$split = split("\=", $value);
$pieces = explode("=", $value);
echo nl2br("$pieces[1]<BR>");

}

?>
</p>
<input name="Submit" type="submit" value="SEND >>">
</p>
</form>

marek_mar
01-28-2005, 04:57 PM
<select name="quantity[<?=$val;?>]" id="quantity[<?=$val;?>]">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>

Should give you array('$val' => 'value')