在过去的四天里,这一直是我的斗争.我真的希望能够解决这个问题,不必在这里问,因为这是很多代码,但我担心我已经尝试过并试图减少问题,这就像我在追逐我的尾巴.我已经消除了尽可能多的代码,我认为我可能已经消除了比我应该更容易看到的内容,所以请随时要求澄清.
概要:
我正在从Google日历中提取日历Feed并填充我自己的日历.我的日历添加了一些功能,其中我有一个"时间轴事件"数据库,就像DaysFromEvent从常规事件中发生一定天数的待办事项.
Feed会被此cron拉入并在Google日历上搜索任何新事件并将其添加到数据库中.(这部分似乎应该正常工作).cron还会查看该ModifiedInGoogle字段以查看事件是否已被修改,如果是,则更新数据库中的事件.这似乎也有效.关键是,如果主事件被修改,那么我还需要看看在数据库中,扳指与主事件相关的任何时间表事件,改变基于其启动时间StartTime + DaysFromEvent
我想我几乎有这个脚本这样做,但我似乎遇到while了if声明中的循环问题.
当我通过脚本运行修改过的事件时,我只能回应: echo "Event ID: ".$tempEventID. ", Promotional Time Line: ".$tempTimelineID.", Parent Event ID: ".$tempParentEventID."<br>";
我应该得到来自while循环的回声,但我不是.我为长话而道歉,甚至为长序代码道歉.我是新手,所以请保持温柔.:)
我准备放弃并聘请某人为我完成这项工作,因为我是一名音乐家,而不是程序员!
if((int)$feed->totalResults>0) { //checking if at least one event is there in this date range
foreach ($feed as $event) { //iterating through all events and pulling all the info to assign the variables below.
$UserID= "42";
$eventDatabase = "events";
//Setting startDate and startTime and endDate and endTime
$StartDate = $event->when[0]->startTime;
$date = strtotime($StartDate);
$StartDate = date('Y-m-d H:i:s',$date);
$StartArray = explode(' ', $StartDate);
$StartTime = $StartArray[1];
$EndDate = $event->when[0]->endTime;
$date = strtotime($EndDate);
$EndDate = date('Y-m-d H:i:s',$date);
$EndArray = explode(' ', $EndDate);
$EndTime = $EndArray[1];
$ModifiedInGoogle = $event->updated->text;
$GoogleID = $event->id;
$EventName = stripslashes($event->title);
$PromotionalTimeLine = "0";
$ParentEventID = "NULL";
$DaysFromEvent = "";
//We are seeing if the Event is already in the database by looking for the googleID
$query = "SELECT * FROM ".$eventDatabase. " WHERE GoogleID='$GoogleID'";
$result = mysql_query($query);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
//This loop UPDATES events if ModifiedInGoogle string is different than what is already in the database
if($ModifiedInGoogle != $row['ModifiedInGoogle']){
//Variables for modifying the timeline start time
$ModifiedEventStartTime = $row['StartTime'];
$tempParentEventID = $tempEventID = $row['EventID'];
$tempTimelineID = $row['PromotionalTimeLine'];
//THIS ECHOS AS I EXPECT IT SHOULD
echo "Event ID: ".$tempEventID. ", Promotional Time Line: ".$tempTimelineID.", Parent Event ID: ".$tempParentEventID."<br>";
//Updates main event when modified in google:
mysql_query("UPDATE ".$eventDatabase." SET
EventName = '$EventName',
StartDate = '$StartDate',
StartTime = '$StartTime',
EndTime = '$EndTime',
EndDate = '$EndDate',
Description = '$Description',
AllDay = '$AllDay',
CreatedOn = '$CreatedOn',
GoogleID = '$GoogleID',
ModifiedInGoogle = '$ModifiedInGoogle'
WHERE GoogleID='$GoogleID' ");
//Query to select the timeline events that have the same ParentEvenID-this is where everything seems to start falling apart...
$query = "SELECT * FROM events WHERE ParentEventID='.$tempParentEventID.' AND GoogleID IS NULL";
$tempresult = mysql_query($query);
while($row = mysql_fetch_array($tempresult, MYSQL_ASSOC)){
$tempEventID = $row['EventID'];
$tempDaysFromEvent = $row['DaysFromEvent'];
$tempStartDate = $row['StartDate'];
//THIS LINE IS NOT ECHOING
echo "EventID: ".$tempEventID.", Start Date: ".$tempStartDate.", Days From Event: ".$tempDaysFromEvent.", Parent Event ID: ".$row['ParentEventID']."<br>";
//IF STARTDATE IS DIFFERENT FROM HOW IT USED TO BE, UPDATE IT.
list($year, $month, $day) = explode("-", $tempStartDate);
$tempStartDate = $tempEndDate = date("Y-m-d", mktime (0,0,0,$month,$day+$tempDaysFromEvent,$year));
echo "TempStart Date:".$tempStartDate."<br>";
//Query to update the startdate of the events
mysql_query("UPDATE".$eventDatabase." SET
StartDate = '$tempStartDate'
WHERE EventID = $tempEventID
");
} //Closes While loop
} //This closes the update if modified if statement
//This loop adds NEW EVENTS
if (!mysql_num_rows($result)) {
//Insert NEW EVENTS
}
} //ends main event loop
} else {
echo "No event found";
}
Run Code Online (Sandbox Code Playgroud)
在线内
$query = "SELECT * FROM events WHERE ParentEventID='.$tempParentEventID.' AND GoogleID IS NULL";
Run Code Online (Sandbox Code Playgroud)
您已包含单引号而非双精度数.你的意思是
$query = "SELECT * FROM events WHERE ParentEventID=".$tempParentEventID." AND GoogleID IS NULL";
Run Code Online (Sandbox Code Playgroud)
或者没有点(如果你想保留分隔符)
$query = "SELECT * FROM events WHERE ParentEventID='$tempParentEventID' AND GoogleID IS NULL";
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1440 次 |
| 最近记录: |