Forum Moderators: coopster
1 camp to input family, 1 to input subfamily, 1 camp to input idx, 1 camp to input item, 1 camp for comp, 1 camp to rule them all.... ooppppsss!
as far as read this will look like this
<form action="add_item.php" method="post">
<input type="hidden" name="family" value="<?=$family?>">
<input type="hidden" name="subfamily" value="<?=$subfamily?>">
<input type="hidden" name="idx" value="<?=$idx?>">
<input type="hidden" name="item" value="<?=$item?>">
<input type="hidden" name="composition" value="<?=$comp?>">
<input type="hidden" name="action" value="clean">
<input type="hidden" name="ini" value="true">
` </form>
so the edge is this in the camp composition [this are medic compunds] I have 300+ and whishing to make a combo box to load this and avoid errors, but load a list this large will be unviable,
Composition : <select name="composition">
<option value="1">blah</option>
<option value="2">blah</option>
<option value="3">and more blah</option>
<option value="300">#*$!XX</option>
</select><br />
SO I was thinking so group my comps in a mysql table taking into groups [0-3] and instead this combo , use the input from family to select from the table all the comps with the same code [hopefully as 70! per family] :
<switch "family" {
case ($family == '0'):
echo'<select name="compund"';
$res=mysql_query("select description from compound where fam_id ='0'");
for($i=0;$i<mysql_num_rows($res);$i++) {
$row=mysql_fetch_assoc($res);
echo"<option>$row[fam_id]</option>";
}
</select>';
break;
case ($family == '1'):
echo'<select name="comp"';
$res=mysql_query("select description from compound where fam_id ='1'");
for($i=0;$i<mysql_num_rows($res);$i++) {
$row=mysql_fetch_assoc($res);
echo"<option>$row[fam_id]</option>";
}
</select>';
break;
case ($family == '2'):
echo'<select name="comp"';
$res=mysql_query("select description from compund where fam_id ='2'");
for($i=0;$i<mysql_num_rows($res);$i++) {
$row=mysql_fetch_assoc($res);
echo"<option>$row[fam_id]</option>";
}
</select>';
break;
case ($familia == '3'):
echo'<select name="comp"';
$res=mysql_query("select description from compound where fam_id ='3'");
for($i=0;$i<mysql_num_rows($res);$i++) {
$row=mysql_fetch_assoc($res);
echo"<option>$row[fam_id]</option>";
}
</select>';
break;
}
and the selection of that beign writed to another table [with all the other data as well]
mysql_connect(mysql_server, username, password);
mysql_select_db(med);
mysql_query("INSERT INTO med (family, subfamily, idx, comp) VALUES ('$family', '$subfamily', '$idx', '$comp')");
but I can do a thing with this php, I mean I cant figure what instruction to add or literally if this is well done (with the exception of the sql code which im 90% sure it is good) so I was wondering if some can give a hint, a template , a hand and a beer would be great!
thanks in advance
There's nothing wrong with your method. You can make it shorter by removing the switch statement and doing one query:
<select name="comp">
<?php
$res=mysql_query("select description from compund where fam_id ='$family'");
for($i=0;$i<mysql_num_rows($res);$i++) {
$row=mysql_fetch_assoc($res);
echo"<option>$row[fam_id]</option>";
}
?>
</select>;