Forum Moderators: coopster
$sql="SELECT * FROM pricelist";and then
$result = mysql_query($sql) or die(mysql_error());
while($row=mysql_fetch_array($result))to access the results. The code works fine but I'd like to perfect the results.
<?=$row['copper_dry_bright']?>
while ($row= mysql_fetch_array($result)) {
echo "<tr>";
foreach ($displayfields as $fieldname) {
$val = (($row[$fieldname]== 0) and array_key_exists($fieldname))?$needs_default[$fieldname]:$row[$fieldname];
echo "<td>$val</td>";
}
echo "</tr>";
}
$query = "UPDATE pricelist SET copper_dry_bright='" . $_POST['copper_dry_bright'] . "', copper_greasy_dry_bright='" . $_POST['copper_greasy_dry_bright'] . "', copper_electro='" . $_POST['copper_electro'] . "', copper_stampings='" . $_POST['copper_stampings'] . "', copper_tinned='" . $_POST['copper_tinned'] . "', copper_new_tube='" . $_POST['copper_new_tube'] . "', copper_hard_drawn='" . $_POST['copper_hard_drawn'] . "', copper_98='" . $_POST['copper_98'] . "', copper_no1='" . $_POST['copper_no1'] . "', copper_no2='" . $_POST['copper_no2'] . "', copper_tanks='" . $_POST['copper_tanks'] . "', copper_braziery='" . $_POST['copper_braziery'] . "', copper_clean_pyro='" . $_POST['copper_clean_pyro'] . "', copper_pvc_pyro='" . $_POST['copper_pvc_pyro'] . "', copper_elements='" . $_POST['copper_elements'] . "', copper_electric_motors='" . $_POST['copper_electric_motors'] . "', copper_fridge_motors='" . $_POST['copper_fridge_motors'] . "', copper_high_grade='" . $_POST['copper_high_grade'] . "', copper_household='" . $_POST['copper_household'] . "', copper_lead_armoured_greasy='" . $_POST['copper_lead_armoured_greasy'] . "', copper_low_grade_armoured='" . $_POST['copper_low_grade_armoured'] . "', brass_mixed='" . $_POST['brass_mixed'] . "', brass_rod_solids='" . $_POST['brass_rod_solids'] . "', brass_no1='" . $_POST['brass_no1'] . "', brass_no2='" . $_POST['brass_no2'] . "', brass_cuttings='" . $_POST['brass_cuttings'] . "', brass_copper_rads='" . $_POST['brass_copper_rads'] . "', brass_commercial_pb='" . $_POST['brass_commercial_pb'] . "', brass_gun_metal_solids='" . $_POST['brass_gun_metal_solids'] . "', brass_gun_metal_borings='" . $_POST['brass_gun_metal_borings'] . "', brass_ab_solids='" . $_POST['brass_ab_solids'] . "', brass_ab_swarf='" . $_POST['brass_ab_swarf'] . "', alu_clean_he9='" . $_POST['alu_clean_he9'] . "', alu_painted_he9='" . $_POST['alu_painted_he9'] . "', alu_thermal_break='" . $_POST['alu_thermal_break'] . "', alu_alloy_wheels='" . $_POST['alu_alloy_wheels'] . "', alu_alloy_radiators='" . $_POST['alu_alloy_radiators'] . "', alu_litho_sheets='" . $_POST['alu_litho_sheets'] . "', alu_commercial_pure='" . $_POST['alu_commercial_pure'] . "', alu_poly_cuts='" . $_POST['alu_poly_cuts'] . "', alu_cast_alloy='" . $_POST['alu_cast_alloy'] . "', alu_old_rolled='" . $_POST['alu_old_rolled'] . "', alu_turnings='" . $_POST['alu_turnings'] . "', alu_copper_rads='" . $_POST['alu_copper_rads'] . "', alu_irony_alloy='" . $_POST['alu_irony_alloy'] . "', alu_zinc='" . $_POST['alu_zinc'] . "', ss_188_solids='" . $_POST['ss_188_solids'] . "', ss_188_turnings='" . $_POST['ss_188_turnings'] . "', ss_316_solids='" . $_POST['ss_316_solids'] . "', ss_316_turnings='" . $_POST['ss_316_turnings'] . "', ss_chrome_iron='" . $_POST['ss_chrome_iron'] . "', lead_contaminated_lead='" . $_POST['lead_contaminated_lead'] . "', lead_clean_lead='" . $_POST['lead_clean_lead'] . "', lead_acid_batteries='" . $_POST['lead_acid_batteries'] . "', other_catalytic_converters='" . $_POST['other_catalytic_converters'] . "', other_cars='" . $_POST['other_cars'] . "', other_engines='" . $_POST['other_engines'] . "', iron_no1_no2='" . $_POST['iron_no1_no2'] . "', iron_burnings='" . $_POST['iron_burnings'] . "', iron_cylinder_iron='" . $_POST['iron_cylinder_iron'] . "', iron_light_iron='" . $_POST['iron_light_iron'] . "', iron_pg1='" . $_POST['iron_pg1'] . "', iron_pg2='" . $_POST['iron_pg2'] . "', iron_profile='" . $_POST['iron_profile'] . "', iron_turnings='" . $_POST['iron_turnings'] . "', iron_shearings='" . $_POST['iron_shearings'] . "', last_updated='" . $date . "' WHERE pricelist_id=1";
$fields=null;
foreach ($myfields as $field) {
if (isset($_POST[$field])) {
$_POST[$field] = ((empty($_POST[$field]) or ($_POST[$field]==0)) and array_key_exists($field))?$needs_default[$field]:$_POST[$field];
$fields .= '`' . $fields . '`=\'' . $_POST[$field] . '\',';
}
}
// Only update if something was set
if ($fields) {
// Normally we'd strip last comma, but since you have another field we don't need to
$sql = "update pricelist set $fields last_updated='" . $date . "' WHERE pricelist_id=1";
// echo $sql; exit; // for testing
echo "updated";
}
else { echo "nothing to update"; }
$fields=null;
foreach ($myfields as $field => $databasefield) {
if (isset($_POST[$field]) {
$fields .= '`' . $databasefield . '`=\'' . $_POST[$field] . '\',';
}
}