1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

create row on per timing

Discussion in 'PHP' started by mark103, Apr 25, 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

    PHP:
    1. <html>
    2.  
    3. <body>
    4.  
    5. <style type="text/css">
    6.  
    7. #channel1 {
    8.  
    9.     position:absolute;
    10.  
    11.     font-family:Arial;
    12.  
    13.     font-size:29px;
    14.  
    15.     font-style:normal;
    16.  
    17.     font-weight:bold;
    18.  
    19.     color:f5fdfd;
    20.  
    21.     text-decoration:none;
    22.  
    23.     text-transform:none;
    24.  
    25.     visibility:visible;
    26.  
    27.     overflow:hidden;
    28.  
    29.     left:35px; top:245px; width:176px; height:50px;
    30.  
    31.     z-index:1;
    32.  
    33. }
    34.  
    35. #programme1 {
    36.  
    37.     position:absolute;
    38.  
    39.     font-family:Arial;
    40.  
    41.     font-size:29px;
    42.  
    43.     font-style:normal;
    44.  
    45.     font-weight:bold;
    46.  
    47.     color:f5fdfd;
    48.  
    49.     text-decoration:none;
    50.  
    51.     text-transform:none;
    52.  
    53.     visibility:visible;
    54.  
    55.     overflow:hidden;
    56.  
    57.     left:427px; top:245px; width:176px; height:50px;
    58.  
    59.     z-index:1;
    60.  
    61. }
    62.  
    63. #programme2 {
    64.  
    65.     position:absolute;
    66.  
    67.     font-family:Arial;
    68.  
    69.     font-size:29px;
    70.  
    71.     font-style:normal;
    72.  
    73.     font-weight:bold;
    74.  
    75.     color:f5fdfd;
    76.  
    77.     text-decoration:none;
    78.  
    79.     text-transform:none;
    80.  
    81.     visibility:visible;
    82.  
    83.     overflow:hidden;
    84.  
    85.     left:765px; top:245px; width:176px; height:50px;
    86.  
    87.     z-index:1;
    88.  
    89. }
    90.  
    91. #programme3 {
    92.  
    93.     position:absolute;
    94.  
    95.     font-family:Arial;
    96.  
    97.     font-size:29px;
    98.  
    99.     font-style:normal;
    100.  
    101.     font-weight:bold;
    102.  
    103.     color:f5fdfd;
    104.  
    105.     text-decoration:none;
    106.  
    107.     text-transform:none;
    108.  
    109.     visibility:visible;
    110.  
    111.     overflow:hidden;
    112.  
    113.     left:1110px; top:245px; width:176px; height:50px;
    114.  
    115.     z-index:1;
    116.  
    117. }
    118.  
    119. #day {
    120.  
    121.     font-family:Arial;
    122.  
    123.     font-size:29px;
    124.  
    125.     font-style:normal;
    126.  
    127.     font-weight:bold;
    128.  
    129.     color:f5fdfd;
    130.  
    131.     text-decoration:none;
    132.  
    133.     text-transform:none;
    134.  
    135.     position:absolute;
    136.  
    137.     visibility:visible;
    138.  
    139.     overflow:hidden;
    140.  
    141.     left:294px; top:180px; width:176px; height:50px;
    142.  
    143.     z-index:0;
    144.  
    145. }
    146.  
    147. #time1 {
    148.  
    149.     font-family:Arial;
    150.  
    151.     font-size:29px;
    152.  
    153.     font-style:normal;
    154.  
    155.     font-weight:bold;
    156.  
    157.     color:f5fdfd;
    158.  
    159.     text-decoration:none;
    160.  
    161.     text-transform:none;
    162.  
    163.     position:absolute;
    164.  
    165.     visibility:visible;
    166.  
    167.     overflow:hidden;
    168.  
    169.     left:424px; top:180px; width:176px; height:50px;
    170.  
    171.     z-index:0;
    172.  
    173. }
    174.  
    175. #time2 {
    176.  
    177.     font-family:Arial;
    178.  
    179.     font-size:29px;
    180.  
    181.     font-style:normal;
    182.  
    183.     font-weight:bold;
    184.  
    185.     color:f5fdfd;
    186.  
    187.     text-decoration:none;
    188.  
    189.     text-transform:none;
    190.  
    191.     position:absolute;
    192.  
    193.     visibility:visible;
    194.  
    195.     overflow:hidden;
    196.  
    197.     left:754px; top:180px; width:176px; height:50px;
    198.  
    199.     z-index:0;
    200.  
    201. }
    202.  
    203. #time3 {
    204.  
    205.     font-family:Arial;
    206.  
    207.     font-size:29px;
    208.  
    209.     font-style:normal;
    210.  
    211.     font-weight:bold;
    212.  
    213.     color:f5fdfd;
    214.  
    215.     text-decoration:none;
    216.  
    217.     text-transform:none;
    218.  
    219.     position:absolute;
    220.  
    221.     visibility:visible;
    222.  
    223.     overflow:hidden;
    224.  
    225.     left:1104px; top:180px; width:176px; height:50px;
    226.  
    227.     z-index:0;
    228.  
    229. }
    230.  
    231. <?php
    232.  
    233. include("get-listing.php");
    234.  
    235. ?>
    236.  
    237. <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>
    238.  
    239. <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>
    240.  
    241. <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>
    242.  
    243. </body>
    244.  
    245. </html>

    get-listing.php

    PHP:
    1. <html>
    2. <body>
    3. <script>
    4.   function ajaxpage(str)
    5.   {
    6.     if (window.XMLHttpRequest)
    7.     { // code for IE7+, Firefox, Chrome, Opera, Safari
    8.       xmlhttp=new XMLHttpRequest();
    9.     }
    10.     else
    11.     {// code for IE6, IE5
    12.       xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
    13.     }
    14.     xmlhttp.onreadystatechange=function()
    15.     {
    16.       if (xmlhttp.readyState==4 && xmlhttp.status==200)
    17.       {
    18.       }
    19.     }
    20.     xmlhttp.open("GET",".php?q="+str,true);
    21.     xmlhttp.send();
    22.   }
    23. </script>
    24. <?php
    25.     define('DB_HOST', 'localhost');
    26.   define('DB_USER', 'myusername');
    27.   define('DB_PASSWORD', 'mypassword');
    28.   define('DB_DATABASE', 'mydbname_tvguide');
    29.      
    30.   $errmsg_arr = array();
    31.   $errflag = false;
    32.   $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    33.    
    34.   if(!$link)
    35.   {
    36.     die('Failed to connect to server: ' . mysql_error());
    37.   }
    38.  
    39.   $db = mysql_select_db(DB_DATABASE);
    40.   if(!$db)
    41.   {
    42.     die("Unable to select database");
    43.   }
    44.  
    45.   if($errflag)
    46.   {
    47.     $_SESSION['ERRMSG_ARR'] = $errmsg_arr;
    48.     echo implode('<br />',$errmsg_arr);
    49.   }
    50.   else
    51.   {
    52.     $qrytable1="SELECT id, channels FROM tvguide";
    53.     $result1=mysql_query($qrytable1) or die('Error:<br />' . $qry . '<br />' . mysql_error());
    54.    
    55.     while ($row = mysql_fetch_array($result1))
    56.     {
    57.       echo "</br>";
    58.       echo "<td>".$row['channels']."</td>";
    59.       echo "</br>";
    60.     }
    61.   }
    62. mysql_close($link);
    63. ?>
    64. </body>
    65. </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 (Text):
    1. <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: Apr 25, 2013
    mark103, Apr 25, 2013 IP
  2. Delta9er

    Delta9er Member

    Messages:
    45
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #2
    If I'm understanding correctly, i'd do something like this:

    Using jQuery, I'd select the text from each element.

    jQuery('#time1').text();

    You can use the .split command then to separate the space from "2:00" and "PM", then again, use .split on the ":" to get the integer.

    I'd post that to my method to then manipulate in PHP. You can use PHP subtraction functionality to get the difference and echo to the browser (within a loop).
    Delta9er, Apr 28, 2013 IP