I have a function in my database class, which gives me a list of events a certain user is attending
function getEventList($uid)
{
$date = date('Y-m-d H:i:s');
$eventSQL = "SELECT em.eventID, e.eventName, e.eventTime FROM eventmembers em INNER JOIN events e ON em.eventID = e.eventID WHERE userIDInvited = :uid";
$eventPrepare = $this->prepare($eventSQL);
$eventPrepare->bindParam(':uid', $uid);
$eventPrepare->execute();
return ($eventPrepare->rowCount() > 0)
? $eventPrepare->fetchAll() : array();
}
To access these results I'm simply doing this
//php
$eventList = $db->getEventList($userid);
if($eventList == NULL){
$smarty->assign('events', 'No events');
}
else{
$count = sizeof($eventList);
for($i = 0; $i < $count; $i++)
{
$smarty->assign('events', $eventList);
}
}
html
<p>MY EVENTS</p>
{foreach from=$events item=result}
<a href="https://localhost/FinalYear/events/{$result.eventID}.php">{$result.eventName}</a><br>
{$result.eventTime}<br>({$result.timeRemain} Days remaining)
<br>
<br>
{/foreach}
What I want to do now is to add, that there is also saying how many days are remaining till this event occurs.
What I did was simply adding this in the for-loop.
$startTimeStamp = strtotime($date);
$endTimeStapm = strtotime($eventList[$i]['eventTime']);
$timeDiff = abs($endTimeStapm - $startTimeStamp);
$numberDays = $timeDiff/86400;
$numberDays = intval($numberDays);
The problem now was, then when, the user attends more than one event, the $numberDays
will be always overwritten. So I tried to add $numberDays
to the end of the current array index. But this gives me just an endless-loop. Without $numberDays
var_dump
gives me this output, when I have to entries
array(2) { [0]=> array(3) { ["eventID"]=> string(1) "1" ["eventName"]=> string(7) "Konzert" ["eventTime"]=> string(19) "2013-03-28 00:00:00" } [1]=> array(3) { ["eventID"]=> string(1) "2" ["eventName"]=> string(4) "Oper" ["eventTime"]=> string(19) "2013-03-30 00:00:00" } } array(2) { [0]=> array(3) { ["eventID"]=> string(1) "1" ["eventName"]=> string(7) "Konzert" ["eventTime"]=> string(19) "2013-03-28 00:00:00" } [1]=> array(3) { ["eventID"]=> string(1) "2" ["eventName"]=> string(4) "Oper" ["eventTime"]=> string(19) "2013-03-30 00:00:00" } }
But I also want at the end of every entry the days remaining. The problem is, that I can't do it in another loop, because that would mean that I would need to make another loop in the .html-file inside the other loop. So it would be run through before the other loop has jumped to its next entry.
Any suggestions how to solve this?
My database-table looks like this
table events
eventID, eventName, eventDescription, eventLocaion, eventTime, eventHost, privacy Settings
table eventmembers
eventID, userIDInvited, InvitationStatus
$smarty->assign('events', $eventList);
each time it will override the previous one and value in events will be always the last one – Prasanth Bendra Mar 26 '13 at 11:55