WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Need help with recurring timer html file (10 posts)

  1. sektor1952
    Member
    Posted 1 year ago #

    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 } ?>
  2. sektor1952
    Member
    Posted 1 year ago #

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

  3. bcworkz
    Member
    Posted 1 year ago #

    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?

  4. sektor1952
    Member
    Posted 1 year ago #

    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.

  5. sektor1952
    Member
    Posted 1 year ago #

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

  6. sektor1952
    Member
    Posted 1 year ago #

    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 } ?>
  7. bcworkz
    Member
    Posted 1 year ago #

    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?

  8. sektor1952
    Member
    Posted 1 year ago #

    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.

  9. bcworkz
    Member
    Posted 1 year ago #

    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.

  10. sektor1952
    Member
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.