I have an array that I have used a range function on:
$year_range = range($start_year1,$end_year3);
print_r($year_range);
Which Returns:
Array (
[0] => 2030
[1] => 2031
[2] => 2032
[3] => 2033
[4] => 2034
[5] => 2035
[6] => 2036
[7] => 2037
)
I have also created a temporary TABLE based on a timestamp.
$date = new DateTime();
$unique_id = $date->getTimestamp();
I know how to create the table with name using the unique timestamp:
$sql = "CREATE TABLE `".$unique_id."`
(
first_year int NOT NULL AUTO_INCREMENT,
second_year varchar(50),
third_year (ID)
)";
etc. What I want to do is create the column names based on those variables within the array $year_range[]. Using a foreach or implode. I'm just not sure how to do it properly.
Something like this:
$columns = implode(" VARCHAR(255),", $year_range) . " VARCHAR(255)";
But how do I use that variable within the SQLi query? Here is what $columns
returns for an array stretching from 2030-2037:
2030 VARCHAR(255),2031 VARCHAR(255),2032 VARCHAR(255),2033 VARCHAR(255),2034 VARCHAR(255),2035 VARCHAR(255),2036 VARCHAR(255),2037 VARCHAR(255)
Thank you for your help.