Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Sep 2008
    Posts
    115
    Thanks
    1
    Thanked 0 Times in 0 Posts

    create row on 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>

    get-listing.php

    PHP Code:
    <html>
     <body>
     <script>
      function ajaxpage(str)
      {
        if (window.XMLHttpRequest)
        { // code for IE7+, Firefox, Chrome, Opera, Safari
          xmlhttp=new XMLHttpRequest();
        }
        else
        {// code for IE6, IE5
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
        }
        xmlhttp.onreadystatechange=function()
        {
          if (xmlhttp.readyState==4 && xmlhttp.status==200)
          {
          }
        }
        xmlhttp.open("GET",".php?q="+str,true);
        xmlhttp.send();
      }
     </script>
     <?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);
    ?>
    </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 mark103; 04-25-2013 at 07:05 PM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    I don't understand a single thing of what you are talking about here.
    The code you have has absolutely no relationship to any type of time or duration. IE: it's impossible for you to get things like this: <span id='time1'>1:00 PM</span> since there is no indication of time ever specified or queried. Finding times and durations would be simple though, if you have a known start time you can use the DateTime class to add x minutes to it using the DateInterval object. Then you can format the time start and end periods. Or, presumably you have a database with a datetime type within it so you could simply generate the end time based on the start and duration during queries.
    As for the images, what are these about? Are you looking for doing something like a gantt chart for the display?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,456
    Thanks
    8
    Thanked 1,084 Times in 1,075 Posts
    Fou-Lu ... this topic was discussed in a previous thread.
    I suggested using timestamps to not only be used for the show times, but to be directly related to the length of the blocks (in pixels).

    ========

    Use UNIX timestamp format, which is an integer that has a one-second resolution.

    One hour is 3600 seconds.

    So if you have two different timestamps, you can accurately determine the time between them. Timestamp format also lends itself to easy graphic displays (time blocks) ... as I mentioned in a previous thread.


    In your database, you can still use "human" readable time, but also add a UNIX timestamp for that time for calculations to your image widths.


    1:00 PM, 1366912800, 2:00 PM, 1366916400

    If you did the math, the difference between those is 3600 seconds.

    That block (the width of the <div> or image) could become 3600/25 (144) pixels wide.
    If the difference was 2 hours, the <div> or image would be 7200/25 (288) pixels wide.

    The width of your blocks, or div sections is always proportional to the length of the show.

  • #4
    Regular Coder
    Join Date
    Sep 2008
    Posts
    115
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks mlseim, could you please post the code for strtotime that I want to check on each time in get-listing.php before I could resizing on each image in test.php?

    thanks!

  • #5
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,456
    Thanks
    8
    Thanked 1,084 Times in 1,075 Posts
    Here is a test script ...

    Copy this to your notepad, save it as "test.php" and upload it ... see what happens.

    PHP Code:

    <?php

    // test script to take show times and create blocks of proportional width

    // shows
    $show="CSI Miami";
    $bg="#eee";
    $begin="1:00 pm";
    $end="2:00 pm";
    echo 
    "<div style='float:left; height:25px; width:".(tstamp($begin,$end)/25)."px; border:1px solid #444; background-color:".$bg."; text-align:center;'>".$show."</div>";

    $show="A Few Good Men";
    $bg="#ddd";
    $begin="2:00 pm";
    $end="4:00 pm";
    echo 
    "<div style='float:left; height:25px; width:".(tstamp($begin,$end)/25)."px; border:1px solid #444; background-color:".$bg."; text-align:center;'>".$show."</div>";

    $show="American Idol";
    $bg="#eee";
    $begin="4:00 pm";
    $end="5:30 pm";
    echo 
    "<div style='float:left; height:25px; width:".(tstamp($begin,$end)/25)."px; border:1px solid #444; background-color:".$bg."; text-align:center;'>".$show."</div>";

    // function to get the number of seconds for each show
    function tstamp($start,$stop){
    $temp1 strtotime(date("Y-m-d")." ".date("H:i"strtotime($start)).":00");
    $temp2 strtotime(date("Y-m-d")." ".date("H:i"strtotime($stop)).":00");
    return 
    $temp2-$temp1;
    }

    ?>

    EDIT:
    You will have a problem with going from 11:00PM to 1:00AM.
    I didn't program any coding for advancing ahead to the next day.
    My example is just a "proof of concept" to show how you can make your boxes sized correctly.
    If you were to fill in some days from 00:00:00 to 23:59:59 it would cover the same amount of screen for each day.
    I guess the tricky part is 00:00:00 (that is the start of a new day or midnight of the previous day, however you look at it).


    .
    Last edited by mlseim; 04-26-2013 at 08:42 PM.


  •  

    Posting Permissions

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