after a while i am trying to solve this problem again, and i found some code wich might be usefull on how to insert multiple records using a date range.
The problem is i cant get the values in the database, and i dont get any errors.
is there anybody who can help me and get this working? if this works we can update the status of more then one day at a time.
thanks in advance
- Code: Select all
<?php
$db = array (
'host' => 'localhost',
'user' => 'test',
'pass' => 'test',
'dbname' => 'calendar'
);
if(!mysql_connect($db['host'], $db['user'], $db['pass']))
{
trigger_error('Connexion error: '.mysql_error());
}
elseif(!mysql_select_db($db['dbname']))
{
trigger_error('Error on selecting database '.mysql_error());
}
else
{
$sql = "SET SESSION sql_mode = 'ANSI,ONLY_FULL_GROUP_BY'";
if(!mysql_query($sql))
{
trigger_error('MySQL in ANSI niet mogelijk');
}
}
// sample data from user input:
$start_date = ('2008-06-01');
$end_date = ('2008-06-05');
$rate = 99;
$company_id = 11;
$car_id = 22;
// create values for each date:
$startTime = strtotime($start_date);
$endTime = strtotime($end_date);
$values = array();
for($time = $startTime; $time <= $endTime; $time = strtotime('+1 day', $time))
{
$thisDate = date('Y-m-d', $time);
$values[] = "($company_id, $car_id, $rate, '$thisDate')";
}
// build the actual query:
$query = sprintf(
"INSERT INTO rates (companyID, carID, rate, date) VALUES\n%s",
implode(",\n", $values)
);
// show what query would look like:
echo "<pre>$query</pre>";
?>