#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2006
    Posts
    167
    Rep Power
    21

    Create row per timing


    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

    PHP Code:
    <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>
    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:

    Code:
    <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>

    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
    Last edited by stephen100; April 25th, 2013 at 12:48 PM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,464
    Rep Power
    594
    Convert your times to a timestamp (use strtotime) which you can then compare or adjust arithmetically.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2006
    Posts
    167
    Rep Power
    21
    i am not really that good to convert the time to a timestamp before resizing on per image.

    Can you please help to post the code?
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,464
    Rep Power
    594
    Read the documentation. Convert the start and end times each to a timestamp. Take the difference to determine the running time.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2006
    Posts
    167
    Rep Power
    21
    I have, but i can't find which strtotime i am looking. can you please post the code that I want to check on each time in get-listing.php using with strtotime before resizing on each image in test.php?

    thanks!
    Last edited by stephen100; April 26th, 2013 at 08:37 AM.
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,464
    Rep Power
    594
    Did you go to the link I gave you for strtotime? I don't understand your question about "which strtotime" as there is only 1.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2006
    Posts
    167
    Rep Power
    21
    Yes I did, but I don't know what one I am looking for in that link. I want to check on each time in get-listing.php using with strtotime before resizing on each image in test.php, could you help me?

    thanks!
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,464
    Rep Power
    594
    I thought I already did. Post the code you are having trouble with (or at least your attempt). I'm not going to write the code for you. If that is what you want, ask in the hire a programmer forum.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2006
    Posts
    167
    Rep Power
    21
    Here is the test.php:

    PHP Code:
    <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;
    }

    <?php
     
    include("get-listing.php");
    ?>

    <span id="programme1"></span>

    <span id="programme2"></span>

    <span id="programme3"></span>

    <div id="image1" 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="image2" style="position:absolute; overflow:hidden; visibility:visible; left:413px; top:245px; width:330px; height:40px; z-index:0"><img src="/images/row1.jpg" alt="" title="" border=0 width=330 height=50></div>

    <div id="image3" style="position:absolute; overflow:hidden; visibility:visible; left:755px; top:245px; width:330px; height:40px; z-index:0"><img src="/images/row1.jpg" alt="" title="" border=0 width=330 height=50></div>

    <div id="image4" style="position:absolute; overflow:hidden; visibility:visible; left:1095px; top:245px; width:370px; height:40px; z-index:0"><img src="/images/row1.jpg" alt="" title="" border=0 width=370 height=50></div>

    </style>
    </body>
    </html>


    get-listing.php

    PHP Code:
     <?php
      define
    ('DB_HOST''localhost');
      
    define('DB_USER''myusername');
      
    define('DB_PASSWORD''mypassword');
      
    define('DB_DATABASE''mydbname_tvguide');
           
      
    $errmsg_arr = array();
      
    $errflag false;
      
    $link mysql_connect(DB_HOSTDB_USERDB_PASSWORD);
        
      if(!
    $link
      {
        die(
    'Failed to connect to server: ' mysql_error());
      }

      
    $db mysql_select_db(DB_DATABASE);
      if(!
    $db
      {
        die(
    "Unable to select database");
      }

      if(
    $errflag
      {
        
    $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
        echo 
    implode('<br />',$errmsg_arr);
      }
      else 
      {
        
    $qrytable1="SELECT id, channels FROM tvguide";
        
    $result1=mysql_query($qrytable1) or die('Error:<br />' $qry '<br />' mysql_error());
         
        while (
    $row mysql_fetch_array($result1))
        {
          echo 
    "</br>";
          echo 
    "<td>".$row['channels']."</td>";
          echo 
    "</br>";
        }
      }
     
    mysql_close($link);
    $data file_get_contents('http://tvlistings.zap2it.com/tvlistings/ZCSGrid.do?stnNum=10179');
     
    preg_match_all('/<span id="row1Time\" class="zc-ssl-pg-time">([^<]+)<\/span>[^>]+>([^<]+)<\/a>/im'$data$matches);
     
    preg_match_all('/<a id="rowTitle1\" class="zc-ssl-pg-title"[^>]*>([^<]+)<\/a>/im'$data$matches1);
     
    $time1 $matches[1];
     
    $titles1 $matches1[1];
     echo 
    "<span id='time1'>".$time1[1]."</span> - <span id='title1'>".$titles1[1]."</span><br></br>";

     
    preg_match_all('/<span id="row2Time\" class="zc-ssl-pg-time">([^<]+)<\/span>[^>]+>([^<]+)<\/a>/im'$data$matches);
     
    preg_match_all('/<a id="rowTitle2\" class="zc-ssl-pg-title"[^>]*>([^<]+)<\/a>/im'$data$matches2);
     
    $time2 $matches[1];
     
    $titles2 $matches2[1];
     echo 
    "<span id='time2'>".$time2[1]."</span> - <span id='title2'>".$titles2[1]."</span><br></br>";

     
    preg_match_all('/<span id="row3Time\" class="zc-ssl-pg-time">([^<]+)<\/span>[^>]+>([^<]+)<\/a>/im'$data$matches);
     
    preg_match_all('/<a id="rowTitle3\" class="zc-ssl-pg-title"[^>]*>([^<]+)<\/a>/im'$data$matches3);
     
    $time3 $matches[1];
     
    $titles3 $matches3[1];
     echo 
    "<span id='time3'>".$time3[1]."</span> - <span id='title3'>".$titles3[1]."</span><br></br>";

     
    preg_match_all('/<span id="row4Time\" class="zc-ssl-pg-time">([^<]+)<\/span>[^>]+>([^<]+)<\/a>/im'$data$matches);
     
    preg_match_all('/<a id="rowTitle4\" class="zc-ssl-pg-title"[^>]*>([^<]+)<\/a>/im'$data$matches4);
     
    $time4 $matches[1];
     
    $titles4 $matches4[1];
     echo 
    "<span id='time4'>".$time4[1]."</span> - <span id='title4'>".$titles4[1]."</span><br></br>";
     
    ?>
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,464
    Rep Power
    594
    I do not see any attempt to use strtotime, anywhere. You did not post the code. Also, get rid of the deprecated MySQL extensions and use PDO.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2006
    Posts
    167
    Rep Power
    21
    Thats because I don't know what strtotime i shoud and where to input them in the code list (test.php or get-listing.php) to compare the time before resizing the image. You still haven't helping me out, please post the code. This is a help forum and you supposed to help me out.

    Comments on this post

    • Jacques1 disagrees : Nobody is "supposed" to help you with anything. If you think you get code for free, you're in the wrong forum.
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 2003
    Posts
    3,464
    Rep Power
    594
    This is a help forum. You are expect to do the work and we can help you over the humps and suggest better techniques. If you want someone to write the code for you, then post in the hire a programmer forum. What is your PHP experience? It sounds like you are trying to write something that is beyond your current skill level and you need to learn more about PHP programming.
    There are 10 kinds of people in the world. Those that understand binary and those that don't.
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2005
    Location
    Vancouver, WA, USA
    Posts
    397
    Rep Power
    189
    Originally Posted by stephen100
    Thats because I don't know what strtotime i shoud and where to input them in the code list (test.php or get-listing.php) to compare the time before resizing the image. You still haven't helping me out, please post the code. This is a help forum and you supposed to help me out.
    GW is trying to help, but is not going to do it for you. He has offered to help, not "supposed to help".
    There is a difference, he can walk away at any time he doesn't feel appreciated, or if he feels you are
    not getting it.

    Read the documentation for strtotime, it is available in many languages other than English. I think
    the language barrier here is making it even more difficult for you.

    Or post in the "hire a programmer" section. For a few $$, someone will happily do it for you, and
    with a smile (though you probably will not see it.)

    Let me recap:
    1) You have a start time, and an end time for each program.
    2) Use strtotime to convert each time into a unix timestamp, which is an integer.
    3) Subtract the start time from the end time. This will give you the running time in seconds.
    4) divide by 60 to convert seconds into minutes.
    Last edited by ttremain; April 26th, 2013 at 10:18 AM.
    Thomas Tremain
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,989
    Rep Power
    375
    Originally Posted by stephen100
    Thats because I don't know what strtotime i shoud and where to input them in the code list (test.php or get-listing.php) to compare the time before resizing the image. You still haven't helping me out, please post the code. This is a help forum and you supposed to help me out.
    if this is a help forum and people are supposed to help each other, Can i have 20$ please? I really need some money.. please? i'll send you my paypal via PM
  28. #15
  29. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2005
    Location
    Vancouver, WA, USA
    Posts
    397
    Rep Power
    189
    As an educational forum, we are here not to do things for each other, but to help people learn to do themselves.

    It's the old: give a fish vs. teach to fish

    If you want to buy a fish, go to eLance.com, if you want a free one, we can try to help you, but we will make you bait your own hook.
    Thomas Tremain

IMN logo majestic logo threadwatch logo seochat tools logo