<html><body><form action="insert-blocktype.php" method="post"> <table> <tr> <td>Block Series:</td> <td> <?php $link = mysql_connect("localhost", "db_user", "password"); mysql_select_db("my_db", $link); $query="SELECT SeriesID,BlockSeries FROM tblblockseries"; $result = mysql_query ($query); echo "<select name=blockseries=''>Block Series</option>"; while($nt=mysql_fetch_array($result)){ echo "<option value=$nt[SeriesID]>$nt[BlockSeries]</option>"; } echo "</select>"; ?> </td> </tr> <tr> <td>Block Type:</td> <td><input type="text" name="blocktype"></td> </tr> <tr> <td>Blocks Per Pallet:</td> <td><input type="text" name="blocksperpallet"></td> </tr> <tr> <td><input type="submit"></td> </tr></form></body></html>
<?php$link = mysql_connect('localhost', 'db_user', 'password');if (!$link) { die('Could not connect: ' . mysql_error());}mysql_select_db("my_db", $link); $insert="INSERT INTO tblblocktype (BlockType, BlocksPerPallet)VALUES('$_POST[blocktype]','$_POST[blocksperpallet]')";if(mysql_query($insert,$link)){ echo "Record added";}else{ die('Error: ' . mysql_error());}mysql_close($link);header('Location: ' . $_SERVER['HTTP_REFERER']);?>
$rows = array();if ($series) { //iterate through $series foreach ($series as $ser) { $id = $ser['SeriesID']; $rows[$id] = array( 'BlockSeries' => $ser['BlockSeries'], //types will contain the entries from the second db table 'types' => array() ); } //iterate through $types if ($types) { foreach ($types as $type) { $id = $type['SeriesID']; if (!isset($rows[$id])) { continue; } //wrong entry, dont use it $rows[$id]['types'][] = array( 'BlockType' => $type['BlockType'], 'BlocksPerPallet' => $type['BlocksPerPallet'] ); } }}