Hello.
I am setting up a Purchase Order form for my company. I would start the mysql data table with such information as PO Number, Supplier, etc etc. Then I would get to the list of 30 possible items, starting with A1, D1, C1, TC1 - in other words, Amount1, Description1, Cost1, and Item Total Cost1 all the way up to A30, D30, C30, TC30.
Whenever the user updates the list, the # after A, D, etc etc would be incremented by 1. Here is the code. $CR is the current item number (Current Row)
if ($_GET['Action'] == 'Update') {
$PO = $_SESSION['Current_PO'];
$Amount = $_POST['Amount'];
$Description = $_POST['Description'];
$Cost = $_POST['Cost'];
$ICost = $_POST['ICost'];
Here is where it can get confusing.

I've set PHP variables to represent the actual column name so the first line would represent A1, next line represent the next column D1, etc etc
$A = 'A' . $CR;
$D = 'D' . $CR;
$C = 'C' . $CR;
$TC = 'TC' . $CR;
The query itself I've actually tested it and does work properly - which is kinda surprising since I didn't know I could manipulate the query the way I did. This query would literally "SET A1 = '$Amount'" on the first add and then "SET A2 = '$Amount' on the next add, etc etc.
$query = "Update purchaseorder SET '$A' = '$Amount', '$D' = '$Description', ";
$query = $query . "'$C' = '$Cost', '$TC' = '$ICost' ";
$query = $query . "where PONumber = '$PO'";
$result = mysql_query($query);
// echo $query;
if ($result) error_message(sql_error());
}
$_SESSION['CR'] ++;
header("location: PurchaseOrders.php?Action=Add");
This is my question then: Is there a better way to do this? As it stands it doesn't seem very efficient (to me). I've tried setting up an array of 30 rows and 4 columns to be posted to the "save to db" page, but it didn't seem to work. Instead it is updating one row at a time (up to 30 rows). Please bear with me and my horrible code, but, like I say, it is working....