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 13 of 13
  1. #1
    Regular Coder
    Join Date
    Sep 2008
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts

    how to make tv guide in php?

    Hi guys,

    I am working on my tv guide website and I start to kick it off. I am going to store the channels name in a mysql database, but I am not sure how to input each channel name in each different div tag like "channel1", "channel2", "channel3", "channel4", "channel5 and "channel6" when I store more than 4 channels in the database. Does anyone know how?

    The second things I want to know how I can check on the tv guide program website to compare the time how long the program will last for so I can then resize the image and input each program title in each text on each image instead of create the rows?

    Any advice would be much appreciated.

    Thanks in advance

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,511
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    Is this your own TV station? Like in a college or something?
    You're not actually recreating a real TV guide for actual TV are you?

  • #3
    Regular Coder
    Join Date
    Sep 2008
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts
    No, I don't own a tv station. I just want to make a tv guide for my own personal use only. So don't tell me what to do even if you try to say i'm not allow to make one.

    By the way, I have stored the channels in mysql database and I can print them out using with this code:

    Code:
    <?php
    session_start();
      define('DB_HOST', 'localhost');
      define('DB_USER', 'mydbusername');
      define('DB_PASSWORD', 'mydbpassword');
      define('DB_DATABASE', 'mydbname');
           
      $errmsg_arr = array();
      $errflag = false;
      $link = mysql_connect(DB_HOST, DB_USER, DB_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>";
        } 
      }
    ?>
    Now I want to output the data from php to html.

    Do you know how?

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,511
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    If you use <div> instead of tables you can dynamically alter the sizes to fit different slots of time. Perhaps do like a grid layout that covers 15 minute resolution across the page. A 1 hour show would span 4 <div> sections. If you use <table> you have a horrible mess of <td> column span problems.

    For now just concentrate on displaying one channel ... one row. If you can get one channel working, you can then get as many as you want.

    Is your guide something you print on paper, or use online with a tablet or laptop? If this is a paper thing you should generate it in PDF ... using FPDF with PHP. Just a thought.


    .
    Last edited by mlseim; 04-04-2013 at 05:31 AM.

  • #5
    Regular Coder
    Join Date
    Sep 2008
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks for your help. How I can dynamically alter the sizes to fit different slots of time when I use <div>?

    As for the channel, how I can display on each channel in each row when I store the channel information in mysql database to output the data from php to html?

    Are there a easy way to do?

    what about if i should use ajax or if i should use php to write the list of channel in xml so i can read it through html?
    Last edited by mark103; 04-04-2013 at 09:32 AM.

  • #6
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,511
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    Can you describe how your MySQL table is set-up?
    What your column names are in the table?
    I see you have channel, what about show titles? and times?

  • #7
    Regular Coder
    Join Date
    Sep 2008
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts
    My mysql db is showing like this:

    Code:
    id     channels    showtitle    description    startdate    enddate
    1     abc family
    2     abc news
    3     CNN
    4     Fox news

  • #8
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,511
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    I assume "startdate" and "enddate" are UNIX timestamps, which decodes to the actual date and time? UNIX timestamp resolution is in seconds.

    So let's do some brainstorming ....

    First of all, we'll pick a day
    April 6, 2013 00:00:00 the day starts - UNIX timestamp: 1365206400
    April 6, 2013 23:59:59 the day ends - UNIX timestamp: 1365292799

    So every day is 86399 seconds long (we'll say 86400)

    If we convert to minutes (86400 / 60), we get: 1440 minutes

    That is a nice number because we can make a line across our browser that is 1440 pixels wide.
    So our time scale above our list of channels will be from 00:00:00 to 23:23:59 ... mark 15 minute intervals?

    So we schedule a show for that day, April 6, 2013 from 1:00PM to 2:59PM
    Those two UNIX timestamps are:
    Start: 1365253200
    End: 1365260399

    By doing some math, we can now determine which pixels will be used for the block.
    The pixel position of those timestamps between the beginning of the day and the end of the day can be determined. Those pixels will in fact be <div> sections with the width's defined by pixels.

    The first pixel for our show is at:

    (showstart - daystart) / 60
    (1365253200-1365206400)/60=780

    The ending of our show is at:

    (showstop - daystart) / 60
    (1365260399 - 1365206400)/60=900 (actually 899.983333333, but round to nearest integer).

    Our show <div> starts at pixel position 780 with a width of 120 pixels.

    That puts a block on our physical browser display in the correct spot on the row.

    The show title itself is contained within the <div> so it appears in the correct box no matter where it lays on the row.

    As you loop through one channel, your query result will be however many shows for that channel.
    Float:left; all the <div>s as you go, making the widths by doing the math for each one.

    I think the 1440 pixel thing would really be a nice way to build and render the guide.
    It will be good on a desktop or laptop, but too wide for a small screen.
    Mathematically, you can scale the line to whatever you want.

    Does that help you with any ideas?



    .
    Last edited by mlseim; 04-05-2013 at 12:12 AM.

  • #9
    Regular Coder
    Join Date
    Sep 2008
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts
    yeah it does help me to give me an idea. can you post the code with that one i really need?

  • #10
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,511
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    I won't have any time to do coding. Perhaps someone else on here might be able to provide some sample scripts? And another question ... how are you entering your data into the MySQL database? Do you have a bunch of channels programmed already, at least for testing purposes?

  • #11
    Regular Coder
    Join Date
    Sep 2008
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I just stored the data in mysql database and I am using ajax to allow me to output the data in php to html. I am testing the output data in php, but i can't be able to read it through html using with ajax.

    Here is the code:

    html:

    Code:
    <html>
    <body>
    
    <style type="text/css">  
    
    #channel1 { 
        font-family:Arial;
        font-size:29px;
        font-style:normal;
        font-weight:bold;
        color:f5fdfd;
        text-decoration:none;
        text-transform:none; 
        position:absolute; 
        visibility:hidden; 
        overflow:hidden; 
        left:194px; top:345px; width:176px; height:50px; 
        z-index:0;
    }
    
    #channel2 { 
        font-family:Arial;
        font-size:29px;
        font-style:normal;
        font-weight:bold;
        color:f5fdfd;
        text-decoration:none;
        text-transform:none; 
        position:absolute; 
        visibility:hidden; 
        overflow:hidden; 
        left:194px; top:345px; width:176px; height:50px; 
        z-index:0;
    }
    
    #channel3 { 
        font-family:Arial;
        font-size:29px;
        font-style:normal;
        font-weight:bold;
        color:f5fdfd;
        text-decoration:none;
        text-transform:none; 
        position:absolute; 
        visibility:hidden; 
        overflow:hidden; 
        left:194px; top:345px; width:176px; height:50px; 
        z-index:0;
    }
    
    #channel4 { 
        font-family:Arial;
        font-size:29px;
        font-style:normal;
        font-weight:bold;
        color:f5fdfd;
        text-decoration:none;
        text-transform:none; 
        position:absolute; 
        visibility:hidden; 
        overflow:hidden; 
        left:194px; top:345px; width:176px; height:50px; 
        z-index:0;
    }
    
    #channel5 { 
        font-family:Arial;
        font-size:29px;
        font-style:normal;
        font-weight:bold;
        color:f5fdfd;
        text-decoration:none;
        text-transform:none; 
        position:absolute; 
        visibility:hidden; 
        overflow:hidden; 
        left:194px; top:345px; width:176px; height:50px; 
        z-index:0;
    }
    
    #channel6 { 
        font-family:Arial;
        font-size:29px;
        font-style:normal;
        font-weight:bold;
        color:f5fdfd;
        text-decoration:none;
        text-transform:none; 
        position:absolute; 
        visibility:hidden; 
        overflow:hidden; 
        left:194px; top:345px; width:176px; height:50px; 
        z-index:0;
    }
    
    <span id="channel1"></span>
    
    <span id="channel2"></span>
    
    <span id="channel3"></span>
    
    <span id="channel4"></span>
    
    <span id="channel5"></span>
    
    <span id="channel6"></span>
    
    function ajaxpage(str)
    {
      if (str == "")
      {
        document.getElementById("channel1").innerHTML = "";
        document.getElementById("channel2").innerHTML = "";
        document.getElementById("channel3").innerHTML = "";
        document.getElementById("channel4").innerHTML = "";
        document.getElementById("channel5").innerHTML = "";
        document.getElementById("channel6").innerHTML = "";
        return;
      }
    
      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)
      {
        document.getElementById("channel1").innerHTML=xmlhttp.responseText;
      }
     }
     xmlhttp.open("GET","tvguide.php?q="+str,true);
     xmlhttp.send();
    }
    </script>
     <form action="tvguide.php" method="post">
    </body>
    </html>

    tvguide.php

    PHP Code:
    <?php
    session_start
    ();
      
    define('DB_HOST''localhost');
      
    define('DB_USER''mydbusername');
      
    define('DB_PASSWORD''mydbpassword');
      
    define('DB_DATABASE''mydbname');
           
      
    $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);
    ?>

  • #12
    Regular Coder
    Join Date
    Sep 2008
    Posts
    116
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I have found a sample script to dynamic the tv schedule in PHP, but I don't know how to work it out with mine when I access to each of those website to output the data in php before I could work it out the length of time to output the data in html.


    Code:
    while [get channel names and id's (order by channel_number]
    {
    	<tr>
    	<td>Channel Name</td>
    	// Your start time:
    	$x = 8;
    	while [SELECT show_name from shows where channel=(channel_id) ORDER BY date_start]
    	{
    		if date_start_hr (convert time like 8:30 to 8.5 and 9:00 to 9==$x
    		{
    			<td[if date_end-date_start = 1hr] ? "colspan=2" : "";>show name</td>
    		}
    		else
    		{
    			<td> none </td>
    		}
    		$x += .5;
    	}
    	</tr>
    }

  • #13
    Regular Coder
    Join Date
    Sep 2011
    Posts
    428
    Thanks
    18
    Thanked 26 Times in 26 Posts
    As far as getting the actual data from the original TV guide list online, take a look at my Basic PHP Functions post and the first two functions should be able to assist you. Be sure to either check the last post or the link to the live file I use for the latest updates.


  •  

    Posting Permissions

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