I have used this piece of code which is working great. It allows me to add different items from combo boxes to my order form. The problem is that i dont know how to extract the data from my db to display in a form view when i want to amend the i.e the number of items. Each record has a different number of items in it but are all lnked to one id. Is this possible to do. Any help on this would go along way. also if the code below helps others please feel free to take as u please.
stdhead("Home");
?>
<script type="text/javascript">
var counter = 0;
function add_phone() {
counter++;
var newFields = document.getElementById('add_phone').cloneNode(true);
newFields.id = '';
newFields.style.display = 'block';
var newField = newFields.childNodes;
for (var i=0;i<newField.length;i++) {
var theName = newField[i].name
if (theName)
newField[i].name = theName + counter;
}
var insertHere = document.getElementById('add_phone');
insertHere.parentNode.insertBefore(newFields,insertHere);
}
</script>
<?
if ($action == "neworder"){
$res50 = mysql_query("SELECT compid FROM eventcompany WHERE company = '$company'") or die;
$res60 = mysql_fetch_array($res50);
$id = $res60['compid'];
if ($id == ''){
begin_frame ("error");
#print"$id";
#print "$company";
print "You have not selected a company";
end_frame();
}else{
$res90 = mysql_query("SELECT * FROM eventcustomers left join eventcompany on eventcompany.compid = eventcustomers.compid WHERE eventcustomers.compid = $id") or die;
$res100 = mysql_fetch_array($res90);
$compid = $res100['compid'];
$company = $res100['company'];
$address = $res100['address'];
$sql = "SELECT * FROM products ORDER BY productid";
$result = mysql_query($sql);
$result1 = mysql_query($sql);
begin_frame ("test3");
print "<b>$company</b><br>$address";
?>
<form name="add_a_phone" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<fieldset>
<div id="phone">
<?
print"<input type=hidden name=compid value=$compid>";
echo "<select name=prodid_0>";
while($row = mysql_fetch_array($result))
{
echo "<option value=\"".$row['productid']."\">".$row['product']."</option> \n ";
}
echo "</select>";
?>
<input type="text" name="productitems_0" value="" />
<input type="text" name="productcost_0" value="" /><br>
</div>
<div id="add_phone" style="display: none;">
<?
echo "<select name=prodid_>";
while($row = mysql_fetch_array($result1))
{
echo "<option value=\"".$row['productid']."\">".$row['product']."</option> \n ";
}
echo "</select>";
?>
<input type="text" name="productitems_" value="" />
<input type="text" name="productcost_" value="" />
<input type="button" value="Remove Item"
onclick="this.parentNode.parentNode.removeChild(this.parentNode);" />
</div>
<input type="button" id="add_phone()" onclick="add_phone()" value="Give me more fields!" /><br>
<input type="submit" name="submit" value="submit" />
</fieldset>
</form>
<?
end_frame();
}}
if(isset($_POST['submit']))
##This checks to make sure submit was clicked
{
echo "You clicked submit!<br>";
echo "Here is your data<br>";
echo "<br>";
if ($_POST['productitems_0'])
##This checks that the proper field has data
{
$continue = FALSE;
$i = 0;
$compid = $_POST['compid'];
while ($continue == FALSE)
{
if (isset($_POST['prodid_'.$i]))
#This looks for an entry after 0 and increments
{
echo $_POST['prodid_'.$i] . " = " . $_POST['productitems_'.$i] . " = " . $_POST['productcost_'.$i] . "<br>";
#Echoing the data
$productid = $_POST['prodid_'.$i];
$productitems = $_POST['productitems_'.$i];
$productcost = $_POST['productcost_'.$i];
$query = "INSERT INTO constructionorderdetails (conorderid, productid, productitems, productcost) VALUES ('$compid','$productid', '$productitems', '$productcost')";
$result = mysql_query($query);
#The four lines above is the example on how the data would be put into a MySQL database. It's not used here
}
else
{
$continue = TRUE;
}
$i++;
}
}
}
stdfoot();