This is a learning project for me and I have made a couple of inquiries on this site already which taught me quite a bit. But I am having problems with the “switch” routine and would appreciate any guidance I can muster. This switch routine was a suggestion but I get errors. I have done quite a bit of research but I still can’t figure out how to accomplish this process. I also don’t understand what the “@” means in “date_create(“@$qucls”)”. It doesn’t seem to matter if it is there or not but this was the suggestion along with the routine.
The queries check out as far as getting me what i want to produce but once I try to update the time strings, it gets bogged down.
The error is, “date_format() expects parameter 1 to be DateTime, boolean given in…”. As far as I know, $qucls should be a string of numbers not a true/false thing. There is definitely a number string in these table fields in the form of int.
Just to repeat other of my posts, I can’t change the database without going over my head. I need to take information from it to make email reminders from a calendar program. The tables are convoluted with unusual forms and lengths of date/time strings so there is much more to this script than appears here. In my process, this is where I am in figuring it out and it’s not too bad for a septuagenarian. I’ll go for cleaning it up after I figure out the processes that get the right outcome.
Here’s the applicable part of the script:
date_default_timezone_set('UTC');
$today = date("Ymd");
mysql_select_db($dbname);
$querydel = "SELECT cal_entry_id, cal_type FROM webcal_entry_log WHERE cal_type = 'D'";
$delqu = mysql_query($querydel);
$i = 0;
while ($row = mysql_fetch_array($delqu, MYSQL_NUM)) {
$qudel[$i] = $row[0];
}
$query1 = "SELECT cal_id, cal_name, cal_date, cal_time, cal_type, cal_description FROM webcal_entry WHERE cal_type = 'M' AND cal_date != ' . $today . ' AND cal_id != " . $qudel[$i];
$wequ1 = mysql_query($query1);
while ($row = mysql_fetch_array($wequ1, MYSQL_NUM)) {
$quid1[$i] = $row[0];
$quname[$i] = $row[1];
$qutime[$i] = $row[3];
$qudesc[$i] = $row[5];
$query2 = "SELECT cal_id, cal_type FROM webcal_entry_repeats WHERE cal_id = " . $quid1[$i];
$wer1 = mysql_query($query2);
if ($row = mysql_fetch_array($wer1, MYSQL_NUM)) {
$qutype[$i] = $row[1];
}
$query3 = "SELECT cal_id, cal_last_sent FROM webcal_reminders WHERE cal_id = " . $quid1[$i];
$wer2 = mysql_query($query3);
if ($row = mysql_fetch_array($wer2, MYSQL_NUM)) {
$qucls[$i++] = $row[1];
}
}
for ($j = 0; $j < $i; $j++) {
}
// date calculations - switch routine
$dateObj = date_create("@$qucls");
switch($qutype) {
case "daily":
date_add($dateObj, date_interval_create_from_date_string("1 day"));
break;
case "weekly":
date_add($dateObj, date_interval_create_from_date_string("1 week"));
break;
case "monthly":
date_add($dateObj, date_interval_create_from_date_string("1 month"));
break;
case "yearly":
date_add($dateObj, date_interval_create_from_date_string("1 year"));
break;
}
$qucls = date_format($dateObj, "U");
Thanks!
Edit: $qucls outputs an array of Unix time stamps as int() type after the query loop ends. Once it encouters – $dateObj = date_create(“@$qucls”) , $dateObj returns false. I can’t seem to find the trick.
In looking at the code, it appears that
$quclsis an array (based on the line$qucls[$i++] = $row[1];).date_createdoes not accept an array as the first parameter.The
@sign would indicate todate_createthat you’re passing a unix timestamp.I’d recommend checking
if ($dateObj === false)to see if date_create is returning a proper value.It also appears that
$qutypeis an array. Not really sure howswitchreacts to being passed an array …Before you try to call date_create … you should
print_r($qutype)andprint_r($qucls)to make sure you know what kind of data you’re dealing with.So, are you trying to do something like this:
You can do a print_r before and after the loop to ensure that all
$quclsvalues are being updated …