SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: I'm an idiot!

  1. #1
    SitePoint Addict
    Join Date
    Jun 2002
    Posts
    240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I'm an idiot!

    Ok guys, I'm an idiot because I can not remember the syntax to accomplish this task: I am trying to write an if/else statement that will perform one task if the time is between 6am and 6pm, the else statement will execute some code if the time is not between 6am and 6pm. I apologize for the simplicity of this request, I just can't seem to remember the function/syntax to make this happen.

  2. #2
    pie??? PIE!!!! rsdl's Avatar
    Join Date
    May 2001
    Location
    Vancouver, BC Canada
    Posts
    502
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    6am and 6pm should of course be the timestamp value or whatever value you're using for time.
    PHP Code:
    if ($time>=6am AND $time<=6pm) {
     
    // do stuff
    }
    else {
      
    // do other stuff

    -rsdl

  3. #3
    SitePoint Addict
    Join Date
    Jun 2002
    Posts
    240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there something that I need to change in the syntax that you provided? I tried it but I am getting a parse error on the first line.

  4. #4
    pie??? PIE!!!! rsdl's Avatar
    Join Date
    May 2001
    Location
    Vancouver, BC Canada
    Posts
    502
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    did you type 6am and 6pm? because as i've said before those two values have to be the time value you're using so you need to change those to the appropriate values.

    post your code here

    -rsdl

  5. #5
    pie??? PIE!!!! rsdl's Avatar
    Join Date
    May 2001
    Location
    Vancouver, BC Canada
    Posts
    502
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    // determine current time
    $time date('H');

    // if time is greater or equal to 6am and less than or equal to 6pm then do stuff
    if ($time>=06 AND $time<=18) {
     
    // do stuff
    }
    else {
     
    // do other stuff


  6. #6
    SitePoint Addict
    Join Date
    Jun 2002
    Posts
    240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh ok, I didn't even see your message on the 1st reply. How do you use the unix timestamp in this case? The code is as follows:
    PHP Code:

    <?
    if ($time>=?? AND time<=??)
    {
    ?>
    <html>
    <head>
    <title>Webcam</title>
    <script LANGUAGE="JavaScript">
    <!-- hide
    // "var speed" is the refresh rate adjustment in seconds.
    var speed = 1;
    var y = 1;
    var x = speed + y;
    var time = x - y;
    var now;
    campicture = new Image();
    function stopClock() {
        x = "off";
        document.form0.clock.value = x;
    }
    function startClock() {
            if (x != "off") {
        x = x - y;
        document.form0.clock.value = x;
        if (x <= 1)
            {
              reload()
            }
        timerID = setTimeout("startClock()", 1000);
            }
    }
    function reload() {
        now = new Date();
        var camImg = "(cam url)" + "?" + now.getTime();
        document.campicture.src = camImg;
        x = speed;
        document.form0.clock.value = x;
                        }
    //end hide -->
    </script>
    </head>
    <body bgcolor="#FFFFFF" onload="startClock()">
    <center><img src="/_template/images/webcam.jpg"></center>
         
            <CENTER>
    <IMG src="webcamstream.jpg" name="campicture" alt="Picture" border=0 reload="60" height=240 width=320>
    </center>

            <CENTER>
              <INPUT type="hidden" name="clock" size="3" value="">
            </CENTER>


    </body>
    </html>

    <?
    }//end if statement
    else {
    ?>
    <html>
    <head><title>WebCam</title></head>
    <body bgcolor="#FFFFFF">
    <center>
    <font size="3">The camera is off right now, please come back between 6am-6pm.</font>
    </center>
    </body>
    </html>

    <?
    }//end else statement
    ?>

  7. #7
    SitePoint Addict
    Join Date
    Jun 2002
    Posts
    240
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, that works. I knew that it was something simple, I just haven't used PHP in a while so I couldn't remember how to do it. I appreciate your help!!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •