在过去的四天里,这一直是我的斗争。我真的希望能够解决这个问题,不必在这里问,因为这是很多代码,但我担心我已经尝试过并试图减少问题,这就像我在追逐我的尾巴。我已经消除了尽可能多的代码 - 我可能已经消除了比我应该更容易看到的内容,所以请随意要求澄清。
概要:
我正在从Google日历中提取日历Feed并填充我自己的日历。我的日历添加了一些功能,其中我有一个“时间轴事件”数据库,就像在常规事件中发生特定天数(DaysFromEvent
)的待办事项。
此cron将提取该Feed并在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";
}
答案 0 :(得分:5)
在行内
$query = "SELECT * FROM events WHERE ParentEventID='.$tempParentEventID.' AND GoogleID IS NULL";
您已包含单引号而非双精度数。你的意思是
$query = "SELECT * FROM events WHERE ParentEventID=".$tempParentEventID." AND GoogleID IS NULL";
或者可能没有点(如果你想保留分隔符)
$query = "SELECT * FROM events WHERE ParentEventID='$tempParentEventID' AND GoogleID IS NULL";
答案 1 :(得分:-1)
首先,跳出来的是while循环: while($ row = mysql_fetch_array($ tempresult,MYSQL_ASSOC))
为了使while循环继续,参数必须为“true”。我不太熟悉php,有些语言接受任何大于0的整数都不是假的,但这可能是错误的来源。
答案 2 :(得分:-1)
它说:
while($row = mysql_fetch_array($tempresult, MYSQL_ASSOC)){
不应该是:
while($row == mysql_fetch_array($tempresult, MYSQL_ASSOC)){
如果那不是意图,那么似乎有一些可疑的东西,因为你不会从某个动作中获得适当的价值,你需要某种查询。