• Resolved sektor1952

    (@sektor1952)


    I am trying add another line to the html file of the reoccuring timeer, I tried duplicating the existing line but I am getting syntax errors and I was wondering anyone could offer suggestions on how to best do that. Thanks in advance and god bless.

    Existing code

    <span id="rt-description">
                   	<?php if(strtotime($event_start) - strtotime($event_start_mid) > 0) { /* MIDWEEK */ ?>
    		<span id="rt-until"><?php echo $instance['event_until_mid']; ?></span>
    		<span id="rt-event"><?php echo $instance['event_name_mid']; ?></span>
    		<span id="rt-on"><?php echo $instance['event_now_mid']; ?></span>
    		<?php } else { ?>
    		<span id="rt-until"><?php echo $instance['event_until']; ?></span>
    		<span id="rt-event"><?php echo $instance['event_name']; ?></span>
    		<span id="rt-on"><?php echo $instance['event_now']; ?></span>
                    <?php } ?>

    I would like to duplicate or add another line to the existing statement with slightly different variables.

    Example code

    <?php if(strtotime($event_start) - strtotime($event_start_mid) > 0) { /* Sunday 830 */ ?>
    		<span id="rt-until"><?php echo $instance['event_until_sun830']; ?></span>
    		<span id="rt-event"><?php echo $instance['event_name_sun830']; ?></span>
    		<span id="rt-on"><?php echo $instance['event_now_sun830']; ?></span>
    
    <?php if(strtotime($event_start) - strtotime($event_start_mid) > 0) { /* MIDWEEK */ ?>
    		<span id="rt-until"><?php echo $instance['event_until_mid']; ?></span>
    		<span id="rt-event"><?php echo $instance['event_name_mid']; ?></span>
    		<span id="rt-on"><?php echo $instance['event_now_mid']; ?></span>
    		<?php } else { ?>
    		<span id="rt-until"><?php echo $instance['event_until']; ?></span>
    		<span id="rt-event"><?php echo $instance['event_name']; ?></span>
    		<span id="rt-on"><?php echo $instance['event_now']; ?></span>
                    <?php } ?>
Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter sektor1952

    (@sektor1952)

    can anybody help with the code or do I need to post in a different forum.

    Moderator bcworkz

    (@bcworkz)

    What is error messages you are getting, which lines do they refer to?

    I don’t see any syntax errors, but your use of $event_start_mid appears inappropriate. Do you not need a different value to yield the right time frame, like $event_start_sun830 or something?

    Thread Starter sektor1952

    (@sektor1952)

    The event_start_mid is correct, basically this is a reoccuring timer for when we broadcast our church services, currently it is coded to allow for 2 different events, but we since added another service and I wanted to update the timer to refelect that.

    I already updated the .php file with the new variable, but when I try to duplicate the _mid lines I get either sudden end of file or unexpected ;, but I can’t find where the issue is so basically I was looking for suggestions on formatting to make sure it needed to be formatted a certain way.

    A clarification on the variables anything _mid stands for midweek service I want to add *_sun830 for the sunday morning 8:30 service and the default variables are for the regular sunday service, any suggestions would be greatly appreciated.

    Thread Starter sektor1952

    (@sektor1952)

    I will post the whole file if need be the code listed above is the part I am having trouble with.

    Thread Starter sektor1952

    (@sektor1952)

    What about if it looked like this, except I think I tried that and I got an unexpceted end error, if I remember correctly.

    <?php if strtotime($event_start) - strtotime($event_start_mid) > 0) { /* Sunday 830 */ ?>
    		<span id="rt-until"><?php echo $instance['event_until_sun830']; ?></span>
    		<span id="rt-event"><?php echo $instance['event_name_sun830']; ?></span>
    		<span id="rt-on"><?php echo $instance['event_now_sun830']; ?></span>
    
    <?php else if(strtotime($event_start) - strtotime($event_start_mid) > 0) { /* MIDWEEK */ ?>
    		<span id="rt-until"><?php echo $instance['event_until_mid']; ?></span>
    		<span id="rt-event"><?php echo $instance['event_name_mid']; ?></span>
    		<span id="rt-on"><?php echo $instance['event_now_mid']; ?></span>
    		<?php } else { ?>
    		<span id="rt-until"><?php echo $instance['event_until']; ?></span>
    		<span id="rt-event"><?php echo $instance['event_name']; ?></span>
    		<span id="rt-on"><?php echo $instance['event_now']; ?></span>
                    <?php } ?>
    Moderator bcworkz

    (@bcworkz)

    I understand now about your variables, your approach is fine. Sorry I caused you to need to explain, I sort of wandered off topic there.

    You don’t want the extra ‘else’ in your last snippet, the midweek stuff will never be output. But it’s good you tried it, because it caused me to see the error in the first snippet. The first curly brace does not have a matching closure! You need this:

    <?php if(strtotime($event_start) - strtotime($event_start_mid) > 0) { /* Sunday 830 */ ?>
    		<span id="rt-until"><?php echo $instance['event_until_sun830']; ?></span>
    		<span id="rt-event"><?php echo $instance['event_name_sun830']; ?></span>
    		<span id="rt-on"><?php echo $instance['event_now_sun830']; ?></span>
                    <?php } ?>
    <?php if(strtotime($event_start) - strtotime($event_start_mid) > 0) { // blah blah...

    I’ve never liked mixing php and html for this reason, it’s very hard to see things like this. I’m not suggesting you change this, except to place the missing curly brace, it’s quite appropriate in this situation. I’m just grousing ?? …or rationalizing missing it the first time around?

    Thread Starter sektor1952

    (@sektor1952)

    That’s ok I probably should have explained it better to begin with anyway and I do have to agree with you 100% about mixing code languages and sorry for the delay in getting back to you I was away for the weekend. So if I understand you correctly just do seperate if statements closing it with this <?php } ?> and remove the last else statement or keep it in there, because I thought that last else statement is like a fall back statement of some sort.

    Moderator bcworkz

    (@bcworkz)

    I hope you had an enjoyable weekend!

    Right, just add the curly brace bit as I illustrated in my previous post. The last else line <?php } else { ?> MUST stay, you are correct, it serves as a fall back. I was saying you need to eliminate the trial ‘else’ you inserted in your attempt to solve the issue, the line that began as <?php else if(strtotime($event_start)// more code... needs to start with the original <?php if(strtotime($event_start)// more code...

    I’m almost certain this will solve your problem. Speaking of weekends, I’ll soon be off on a “weekend” myself, so I may not see your response for a while, but I will check back in eventually. Good luck!

    P.S. There is a way to roll the codes together, since the ‘if’ conditions are identical, which is what you may have been angling for by omitting the closing curly brace (we know now that wasn’t how to do it), but the changes are more complex, and you would not be able to physically separate the 8:30 output from the rest of the output, should that become desirable. I thus decided to stick with the easiest fix which allows for easier page layout changes, even if it’s a bit less efficient.

    Thread Starter sektor1952

    (@sektor1952)

    Enjoy your time off and thanks, it worked sort of I didn’t get the error any more but it wasn’t working quite right I think it maybe the limitations of the code.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Need help with recurring timer html file’ is closed to new replies.