how to compare the timing?

Discussion in 'PHP' started by mark103, Apr 27, 2013.

  1. #1
    Hi guys,

    I am working on my tv guide website that I output the data to my php from mysql database. I want to know how i can work it out the tv time for per programme how long they would last for, e.g 30 mins, 1 hour...etc

    <html>
    
    <body>
    
    <style type="text/css">
    
    #channel1 {
    
        position:absolute;
    
        font-family:Arial;
    
        font-size:29px;
    
        font-style:normal;
    
        font-weight:bold;
    
        color:f5fdfd;
    
        text-decoration:none;
    
        text-transform:none;
    
        visibility:visible;
    
        overflow:hidden;
    
        left:35px; top:245px; width:176px; height:50px;
    
        z-index:1;
    
    }
    
    #programme1 {
    
        position:absolute;
    
        font-family:Arial;
    
        font-size:29px;
    
        font-style:normal;
    
        font-weight:bold;
    
        color:f5fdfd;
    
        text-decoration:none;
    
        text-transform:none;
    
        visibility:visible;
    
        overflow:hidden;
    
        left:427px; top:245px; width:176px; height:50px;
    
        z-index:1;
    
    }
    
    #programme2 {
    
        position:absolute;
    
        font-family:Arial;
    
        font-size:29px;
    
        font-style:normal;
    
        font-weight:bold;
    
        color:f5fdfd;
    
        text-decoration:none;
    
        text-transform:none;
    
        visibility:visible;
    
        overflow:hidden;
    
        left:765px; top:245px; width:176px; height:50px;
    
        z-index:1;
    
    }
    
    #programme3 {
    
        position:absolute;
    
        font-family:Arial;
    
        font-size:29px;
    
        font-style:normal;
    
        font-weight:bold;
    
        color:f5fdfd;
    
        text-decoration:none;
    
        text-transform:none;
    
        visibility:visible;
    
        overflow:hidden;
    
        left:1110px; top:245px; width:176px; height:50px;
    
        z-index:1;
    
    }
    
    #day {
    
        font-family:Arial;
    
        font-size:29px;
    
        font-style:normal;
    
        font-weight:bold;
    
        color:f5fdfd;
    
        text-decoration:none;
    
        text-transform:none;
    
        position:absolute;
    
        visibility:visible;
    
        overflow:hidden;
    
        left:294px; top:180px; width:176px; height:50px;
    
        z-index:0;
    
    }
    
    #time1 {
    
        font-family:Arial;
    
        font-size:29px;
    
        font-style:normal;
    
        font-weight:bold;
    
        color:f5fdfd;
    
        text-decoration:none;
    
        text-transform:none;
    
        position:absolute;
    
        visibility:visible;
    
        overflow:hidden;
    
        left:424px; top:180px; width:176px; height:50px;
    
        z-index:0;
    
    }
    
    #time2 {
    
        font-family:Arial;
    
        font-size:29px;
    
        font-style:normal;
    
        font-weight:bold;
    
        color:f5fdfd;
    
        text-decoration:none;
    
        text-transform:none;
    
        position:absolute;
    
        visibility:visible;
    
        overflow:hidden;
    
        left:754px; top:180px; width:176px; height:50px;
    
        z-index:0;
    
    }
    
    #time3 {
    
        font-family:Arial;
    
        font-size:29px;
    
        font-style:normal;
    
        font-weight:bold;
    
        color:f5fdfd;
    
        text-decoration:none;
    
        text-transform:none;
    
        position:absolute;
    
        visibility:visible;
    
        overflow:hidden;
    
        left:1104px; top:180px; width:176px; height:50px;
    
        z-index:0;
    
    }
    
    <?php
    
    include("get-listing.php");
    
    ?>
    
    <div id="image1" style="position:absolute; overflow:hidden; visibility:visible; left:21px; top:245px; width:374px; height:40px; z-index:0"><img src="/images/row1_yellow.jpg" alt="" title="" border=0 width=374 height=50></div>
    
    <div id="image2" style="position:absolute; overflow:hidden; visibility:visible; left:21px; top:295px; width:374px; height:40px; z-index:0"><img src="/images/row1.jpg" alt="" title="" border=0 width=374 height=50></div>
    
    <div id="image3" style="position:absolute; overflow:hidden; visibility:visible; left:21px; top:345px; width:374px; height:40px; z-index:0"><img src="/images/row1.jpg" alt="" title="" border=0 width=374 height=50></div>
    
    </body>
    
    </html> 
    PHP:
    I am using the row1 as per image to resize it for per programme, but i have no idea how i can compare with each timing for per programme before resizing on per image.

    here is what my php displaying:

    <span id='time1'>1:00 PM</span> - <span id='title1'>SportsCenter</span><br></br><span id='time2'>2:00 PM</span> - <span id='title2'>SportsCenter</span><br></br><span id='time3'>3:00 PM</span> - <span id='title3'>SportsCenter Special: On the Clock</span><br></br><span id='time4'>4:00 PM</span> - <span id='title4'>NFL Live</span><br></br>
    Code (markup):

    I want to know how to work it out on per timing how long the programme will last for, e.g I want to work it out between time1 and time2 to find out how long it will last which it make 60 mins.

    Does anyone know how i can compare with each timing on per programme before resizing on per image?

    Any advice would be much appreicated.

    Thanks in advance
     
    mark103, Apr 27, 2013 IP
  2. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #2
    Well... so far you're just showing output, not your php -- without seeing what should be generating the markup, it's hard to weigh in on what the markup should be. Generally if you aren't storing the length in your database (which to be frank is foolish) you'd always have to 'lag-behind' the output, and the last one in the result set couldn't have a length.

    But that markup... uhg. Inlined redundant style, absolute positioning on what I suspect should be stacked in flow... the CSS is no real winner either with the endless/pointless redundancies.

    Do you have a live copy or even just a screencap of what you want it to look like, and a complete list of what data is available from your PHP?

    You're really not showing us enough to offer any meaningful help.
     
    deathshadow, Apr 27, 2013 IP
  3. ratan1980

    ratan1980 Member

    Messages:
    46
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    28
    #3
    use time() function. store value using this function at the beginning in variable var1 and at the end of the program use it to store current time in variable var2. then subtract var1 from var2 and store it in another variable i.e var1=time(); at end of the program. var2=time(); duration= var2-var1; if require use thread to know when the program ends.
     
    ratan1980, Apr 29, 2013 IP
  4. edduvs

    edduvs Well-Known Member

    Messages:
    394
    Likes Received:
    31
    Best Answers:
    3
    Trophy Points:
    160
    #4
    Pro tip of the day.. if you already have <style> tags in your page avoid using style="" attribute inline. Use classes to make a main general stylesheet for all the elements, then create separate ones with individual properties.

    Now, coming back on topic, think at bigger scale, the website as 1000 visitors, each refreshes the tv schedule about 10 times. That implies aproximatively 5000 requests, without even bothering to speak how long it takes the script to make it's math per frame.

    Now, there are is another way, get the file's FPS and frames number then just do
    <?php
    $seconds = $file['framesCount']/$file['fps'];
    echo floor($seconds/60); // to minutes
    ?>
    PHP:
     
    edduvs, Apr 29, 2013 IP