Log in

View Full Version : Need help with PHP declations ($var = ) stuff - RESOLVED



Relics
04-06-2010, 05:42 AM
I have a problem that I need someone who knows PHP to help me with.

I am creating a theme for Wordpress and I've created a admin options panel where you can set up some options on the theme. I have a php script on a page that displays only when certain dates are entered in the "$start" declaration. I need to change to month and day choices from the numbers to the declarations from the options panel. I've included the script below. If someone could show me the correct code to replace the "-04-04" in the "$start" declaration to use the "$tohh_month_start" and the "$tohh_day_start" instead of the numbers, I would greatly appreciate it.


<?php
$tohh_timezone = get_option('tohh_ticketbuy_timezone');
$tohh_month_start = get_option('tohh_ticketbuy_month_start');
$tohh_day_start = get_option('tohh_ticketbuy_day_start');
$tohh_month_stop = get_option('tohh_ticketbuy_month_stop');
$tohh_day_stop = get_option('tohh_ticketbuy_day_stop');

date_default_timezone_set('$tohh_timezone');

$today = strtotime(date('Y-m-d'));
$start = strtotime(date('Y') . '-04-04');
$end = strtotime(date('Y') . '-04-20');

if($today >= $start && $today <= $end) { ?>

<!-- START -->
It works!
<!-- END -->

<?php } ?>

Relics
04-06-2010, 05:54 AM
Naturally after I post this, I figure out a working version. I'll post it here for review. Let me know if I'm still doing this wrong or there is a better way to go about doing this. I'm still learning PHP and could use the pointers.

<?php
$tohh_timezone = get_option('tohh_ticketbuy_timezone');
$tohh_month_start = get_option('tohh_ticketbuy_month_start');
$tohh_day_start = get_option('tohh_ticketbuy_day_start');
$tohh_month_stop = get_option('tohh_ticketbuy_month_stop');
$tohh_day_stop = get_option('tohh_ticketbuy_day_stop');

date_default_timezone_set('$tohh_timezone');

$today = strtotime(date('Y-m-d'));
$start = strtotime(date('Y-'.$tohh_month_start.'-'.$tohh_day_start));
$end = strtotime(date('Y-'.$tohh_month_stop.'-'.$tohh_day_stop));

if($today >= $start && $today <= $end) { ?>

<!-- START -->
It works!
<!-- END -->

<?php } ?>

djr33
04-06-2010, 05:59 AM
That's completely correct, assuming everything is consistent with formatting of the variables, etc.
Note that you can now mark this discussion as "Resolved" by editing your first post.