8 Replies - 698 Views - Last Post: 13 February 2012 - 03:43 AM Rate Topic: -----

#1 Euskadi  Icon User is offline

  • New D.I.C Head

Reputation: -4
  • View blog
  • Posts: 16
  • Joined: 01-February 12

Can someone talk me through this code?

Posted 10 February 2012 - 09:25 AM

It's part of a vBulletin script so while it's not 'pure' PHP I'm sure someone au fait with the language will be able to understand it.

Basically it is code which checks a calendar for events, and outputs the following event complete with a countdown timer. The problem is that it seems to overlook an event if it is the following day, for example even though there is an event on the calendar on tomorrow's date, it thinks the next event is the one after that (next weekend).

ob_start();
global $db,$vbulletin;
$event_calendarid="2";
$no_events_message="<div style='width: 100%; text-align: center; font-weight: bold'>TBA</div>";
$today_date = mktime(0, 0, 0, date(date("m")), date((date("d"))),  date(date("y")));
$and=" and dateline_from > '".$today_date."'";

$getevents=$db->query_read("SELECT eventid, title, dateline_from from " . TABLE_PREFIX . "event WHERE calendarid='".$event_calendarid."' $and order by dateline_from ASC LIMIT 2");
$count=1;
if(!$db->num_rows($getevents))
{
echo $no_events_message;
} 
else
{
echo "<script type='text/javascript'>\n";
WHILE ($events=$db->fetch_array($getevents))
{
$event_title=$events['title'];
$event_date = vbdate('U',$events['dateline_from'], false,true,false,true)-vbdate('U');
if($count==1)
{
echo "var CountDownTimer=new CountDown('CountDownToChange',1,'".$event_title."<br />','".$event_date."','ywdhms',1)\n";
}
else
{
echo "CountDownTimer.AddNewEvent('".$event_title."<br />','".$event_date."','ywdhms',".$count.")\n";
}
$count++;
}
}
echo "CountDownTimer.DisplayTime(FormatResults)\n";
echo "</script>\n";
$db->free_result($getevents);
unset($events);
$output=ob_get_contents();
ob_end_clean();


How could I change this so it recognises not only tomorrow's events, but also today's i.e. if there is an events scheduled for today's date, it will display that.

Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Can someone talk me through this code?

#2 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2889
  • View blog
  • Posts: 10,002
  • Joined: 08-August 08

Re: Can someone talk me through this code?

Posted 10 February 2012 - 09:51 AM

Did you write this code? If you did, why can't you make this simple change?
Was This Post Helpful? 1
  • +
  • -

#3 Euskadi  Icon User is offline

  • New D.I.C Head

Reputation: -4
  • View blog
  • Posts: 16
  • Joined: 01-February 12

Re: Can someone talk me through this code?

Posted 10 February 2012 - 09:58 AM

View PostCTphpnwb, on 10 February 2012 - 09:51 AM, said:

Did you write this code? If you did, why can't you make this simple change?

Uh, no I didn't.. that's why I'm asking for help?
Was This Post Helpful? -1
  • +
  • -

#4 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2889
  • View blog
  • Posts: 10,002
  • Joined: 08-August 08

Re: Can someone talk me through this code?

Posted 10 February 2012 - 10:18 AM

This forum is for people looking to learn more about writing PHP code. If you want code written for you then you should try the Post a Job forum.
Was This Post Helpful? 3
  • +
  • -

#5 Euskadi  Icon User is offline

  • New D.I.C Head

Reputation: -4
  • View blog
  • Posts: 16
  • Joined: 01-February 12

Re: Can someone talk me through this code?

Posted 10 February 2012 - 10:44 AM

View PostCTphpnwb, on 10 February 2012 - 10:18 AM, said:

This forum is for people looking to learn more about writing PHP code. If you want code written for you then you should try the Post a Job forum.

As I'm sure you can see, the code is already written. I'm asking for help understanding it so I can solve my problem.

Thanks once again for your helpful input.
Was This Post Helpful? -1
  • +
  • -

#6 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2889
  • View blog
  • Posts: 10,002
  • Joined: 08-August 08

Re: Can someone talk me through this code?

Posted 10 February 2012 - 11:15 AM

As I'm sure you've read, the rules of the forum require that you show some effort. You need to do more than post code you didn't write. Show us what you've tried, and why you think it hasn't worked.
Was This Post Helpful? 1
  • +
  • -

#7 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 789
  • View blog
  • Posts: 1,676
  • Joined: 30-January 09

Re: Can someone talk me through this code?

Posted 11 February 2012 - 02:02 PM

View PostEuskadi, on 11 February 2012 - 06:12 PM, said:

...I'll go elsewhere

My first suggestion would be the vBulletin forums.

This post has been edited by e_i_pi: 11 February 2012 - 02:02 PM

Was This Post Helpful? 4
  • +
  • -

#8 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6035
  • View blog
  • Posts: 23,417
  • Joined: 23-August 08

Re: Can someone talk me through this code?

Posted 11 February 2012 - 02:15 PM

I've hidden your profanity-laden reply. Note in the future that when you're working with a third-party product such as vBulletin you're always likely to get better help at the source, to which the brilliant e_i_pi has pointed you. The majority of us have no earthly idea how some proprietary function like vbdate() works, which seems pivotal to your issue.
Was This Post Helpful? 1
  • +
  • -

#9 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 789
  • View blog
  • Posts: 1,676
  • Joined: 30-January 09

Re: Can someone talk me through this code?

Posted 13 February 2012 - 03:43 AM

He could have, of course, had a cursory glance at the code and changed this line:
$and=" and dateline_from > '".$today_date."'";


...to this...
$and=" and dateline_from >= '".$today_date."'";


...but I guess that would have been asking a bit much of his precious time.
Was This Post Helpful? 2
  • +
  • -

Page 1 of 1