In the following code, columns in my database which don't yet exist, and which must exist before the rest of the script can continue, get added to the database.
The column names that must be created are in an array called $ColumnsNotYetExistingArray. The number of them is $NumColumnsNotExisting.
I create the new columns in the database like this:
if ($NumColumnsNotExisting > 0)
{
$count = 0;
while ($count < $NumColumnsNotExisting)
{
$ThisNotExisting = ($ColumnsNotYetExistingArray[$count]);
$AddNewColumnsQuery = "ALTER TABLE productstable ADD COLUMN $ThisNotExisting decimal(6,2) NOT NULL default '0.00'";
mysql_query($AddNewColumnsQuery);
$count++;
}
}
The corresponding values of the $ColumnsNotYetExistingArray are in an array called $PriceOptionsPricesArray (both arrays will always have the same number of elements, and their corresponding indexes are associated as pairs).
I then want to add new the values from the elements in $PriceOptionsPricesArray to the newly created columns taken from the elements of $ColumnsNotYetExistingArray, but here I'm stuck. Since I'm also adding other stuff at the same time, so far I have:
$InsertNewValuesQuery = "INSERT INTO productstable VALUES ('$Nothing','$NextSKU', '$UniqueImageID', '$ProductCategory', '$ProductTitleA', '$ProductDescriptionA')";
Now, after the insertion of $ProductDescriptionA at the end, I also want to add the values from the elements of the array $PriceOptionsPricesArray to the new columns that have been created from the elements of $ColumnsNotYetExistingArray, but I don't how to do it.
I know I have the information as to how many new columns have just been created (in $NumColumnsNotExisting), and I know that the elements of $PriceOptionsPricesArray must somehow be pushed in sequence onto the end of the query, but I don't know how to do that!
Glad for any help!