Refreshing new content.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kaosalrim
Forum Newbie
Posts: 10
Joined: Tue Jul 14, 2009 2:48 pm

Refreshing new content.

Post by kaosalrim »

Hi I am currently working on a php script that should pull dates and events from a Microsoft access database. Everything works fine, but I am stuck on a problem. The screen that displays the meetings is the screen int he entrance hall, so it cannot be scrolled if more then 9 meetings are displayed. The page should refresh every 20 seconds if theres more then 9 meetings it should refresh with the next content and also in both cases at the end of 20 seconds it should refresh with displaying a french version of the same content. So it's kind of in a loop, that refreshes every 20 seconds going through all the english content and then going through the french then back to english, and so forth.

Anyone has any idea how can i do this? I tried several things but it doesn't work. If I put a refresh call in the header it just refreshes the same page.

Code: Select all

<?php
    //header( 'refresh: 60; ' );
    date_default_timezone_set("America/Montreal");
    $i = 1;
    $bool = true;
    $count = 1;
    $content_block = "
    <html>
    <head>
    <meta http-equiv=\"content-type\" content=\"text/html; charset= iso-8859-1\">
    <title>Meeting Display System</title>
    </head>
    <body background=\"background.jpg\" text=\"#006699\" link=\"#0000ff\" vlink=\"#ff00ff\" rightmargin=0>
    <BR>
    <TABLE>
    <TR><TD width=100 valign=top><CENTER><IMG height=65 src=\"cummings3.jpg\" width=75 ></CENTER></TD>
    <TD width=320><CENTER><FONT face=\"Book Antiqua\" color=\"#F3F49C\" size = 6><I>
    Maison Cummings House</I></FONT></CENTER></TD><TD><CENTER>
    <FONT face=\"Book Antiqua\" color=\"#F3F49C\" size=3>". date("l, F d, Y")."</FONT><BR>
    <FONT face=\"Book Antiqua\" color=\"#F3F49C\" size=5><CENTER>". date("h:i A")."</CENTER></FONT></CENTER></TD></TR></TABLE>
    <TABLE border= 1 bordercolor=black><TR><TD><center>
    <font size=5.5 color=black><B><U>Time</B></font></center></U></TD><td width=500>
    <center><font size=5 color=black><B><U>Meeting</B></font></center></U></td>
    <TD width=200><font size=5 color=black><B><U>Room</B></font><CENTER></CENTER></U></TD></TR>";
    
    $conn = new COM("ADODB.Connection") or die("Cannot start ADO"); 
    // Microsoft Access connection string.
    $conn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:\\Inetpub\\wwwroot\\MeetingSystemTest\\Meetingsystem\\meeting.mdb");
    $rs = $conn->Execute("SELECT Time, Meeting, Room, Date FROM Event WHERE Date Like '%" .date("n/d/Y"). "%' ORDER BY Time");
        
    while (!$rs->EOF) 
        {
            $time = strtotime($rs->Fields('Date') . ' ' . $rs->Fields('Time')); 
            $timedisp = strtotime($rs->Fields("Time")->Value);
            if ($time > time())
                {
                    $count = $count + 1;
                    if($i == 1)
                    {
                        $i = $i + 1;
                        $content_block .="<TR bgcolor=#FFFFFF><TD><Font color=black><Center>
                        <font size=4 face=Arial>".date("H:i",$timedisp).
                        "</TD><TD><Font color=black size=4 face=Arial>&nbsp;"
                        .$rs->Fields("Meeting")->Value."</TD><TD>
                        <Font color=black size=4 face=Arial>".$rs->Fields("Room")->Value."</TD</TR>";
                        
                    }
                    else
                    {
                        $i = $i - 1;
                        $content_block .= "<TR bgcolor=#3E797D><TD><Font color=black><Center>
                        <Font size=4 face=Arial>".date("H:i",$timedisp).
                        "</TD><TD><Font color=black size=4 face=Arial>&nbsp;"
                        .$rs->Fields("Meeting")->Value."</TD><TD>
                        <Font color=black size=4 face=Arial>".$rs->Fields("Room")->Value."</TD</TR>";
                    }                     
                }
            $rs->MoveNext();
        }
        for($x = $count; $x <= 9; $x++)
        {
            if($i==1)
            {
                $i = $i + 1;
                $content_block .= "<TR bgcolor=#FFFFFF><TD><Font color=black><Center>
                            <Font size=4 face=Arial>&nbsp;
                            </TD><TD><Font color=black size=4 face=Arial>&nbsp;</TD><TD>
                            <Font color=black size=4 face=Arial>&nbsp;</TD</TR>";
            }
            else
            {
                $i=$i-1;
                $content_block .= "<TR bgcolor=#3E797D><TD><Font color=black><Center>
                            <Font size=4 face=Arial>&nbsp;
                            </TD><TD><Font color=black size=4 face=Arial>&nbsp;</TD><TD>
                            <Font color=black size=4 face=Arial>&nbsp;</TD</TR>";
            }
        }
    $rs->Close();
    $content_block .= "</table></body></html>";
    header("refresh: 20;location:phptest.php?$content_block");
    
?>
this is the code i currently have.
Last edited by Benjamin on Thu Jul 16, 2009 7:44 pm, edited 2 times in total.
Reason: Added [code=php] tags.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Refreshing new content.

Post by jackpf »

Is there such a thing as a refresh header?

You could just use a meta tag or javascript. Although, this sounds like a good job for ajax...it would decrease server load, and make it a lot quicker.
aliciadg
Forum Newbie
Posts: 16
Joined: Tue Jul 14, 2009 3:39 pm

Re: Refreshing new content.

Post by aliciadg »

Have you tried the redirect in a meta tag?

Code: Select all

<META 
http-equiv="refresh" 
content="20;URL=http://www.someurl.com/">
I don't know if this would work for you though if your wanting it completely automated. If you use this tag then what happens if you have less than 9 meetings in a day?
kaosalrim
Forum Newbie
Posts: 10
Joined: Tue Jul 14, 2009 2:48 pm

Re: Refreshing new content.

Post by kaosalrim »

well it still has to load the same content but in french even if there's less then 9 meeting.. it's just when there's more then 9 then it has to display 9 meeting on first english page, then let's say the rest 5 on the other , then do the same thing but in french. This is where I get stuck.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Refreshing new content.

Post by jackpf »

Could you not get all the meetings, divide and ceil the number of meetings by nine, put each group into a sessions, and then refresh with an incrementing value in the url, and then show whatever session is in the url.

Is this what you mean? If not, I have misunderstood and I apologise :)
kaosalrim
Forum Newbie
Posts: 10
Joined: Tue Jul 14, 2009 2:48 pm

Re: Refreshing new content.

Post by kaosalrim »

does that mean i have to create a session variable for every set of 9 meeting + same but in french?
How would u refresh it with a different url every time? doesn't that mean that there will be 1 page for each set?
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Refreshing new content.

Post by jackpf »

No, say like this:

Code: Select all

echo '<script>window.onload = function()
{
setTimeout("window.location = \''.htmlentities($_SERVER['PHP_SELF']).'?page='.((int) $_GET['page'] + 1).'\'", 60000);
}';
 
And then you can display the correct session with $_GET['page'].

Wtf my slashes have been mysteriously removed from my post. Them single quotes are supposed to be escaped btw.
Last edited by jackpf on Thu Jul 16, 2009 11:08 am, edited 1 time in total.
spider.nick
Forum Commoner
Posts: 72
Joined: Wed Jul 15, 2009 12:22 pm
Location: Overland Park, KS

Re: Refreshing new content.

Post by spider.nick »

FYI, using Access as a viable database solution is a mistake. We have a hosting client that is medium traffic, and we are constantly having issues with the DB not freeing up the memory it uses. Granted, their coding is probably not optimized, but it would be much wiser to use MSSQL or MySQL.

<rant />

Nick
kaosalrim
Forum Newbie
Posts: 10
Joined: Tue Jul 14, 2009 2:48 pm

Re: Refreshing new content.

Post by kaosalrim »

jackpf wrote:No, say like this:

Code: Select all

echo '<script>window.onload = function()
{
setTimeout("window.location = \''.htmlentities($_SERVER['PHP_SELF']).'?page='.((int) $_GET['page'] + 1).'\'", 60000);
}';
 
And then you can display the correct session with $_GET['page'].

Wtf my slashes have been mysteriously removed from my post. Them single quotes are supposed to be escaped btw.
doesn't that still means that there will be a session variable for each group of 9?
and will it go back to the first page?
cause at the end what it should do is : Page1content->Page2content->back to page1content.
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Refreshing new content.

Post by jackpf »

Well yeah, that's just the basic idea, you'll obviously have to adapt it and stuff.

You could easily do that with something like this:

Code: Select all

 
$next_page = ($_GET['page'] < $_SESSION['total_pages'] ? $_GET['page'] + 1 : 1;
 
kaosalrim
Forum Newbie
Posts: 10
Joined: Tue Jul 14, 2009 2:48 pm

Re: Refreshing new content.

Post by kaosalrim »

ok thx I will try that out.
kaosalrim
Forum Newbie
Posts: 10
Joined: Tue Jul 14, 2009 2:48 pm

Re: Refreshing new content.

Post by kaosalrim »

Code: Select all

<?php
session_start();
    date_default_timezone_set("America/Montreal");
    $count = 0;
    $maxList = 1;
    $pageTotal = 1;
    $fillCount = 0;
    $countEntries = 0;
    $meetings = array();
    $all = array();
    $content = "";
    $conn = new COM("ADODB.Connection") or die("Cannot start ADO"); 
    // Microsoft Access connection string.
    $conn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:\\Inetpub\\wwwroot\\MeetingSystemTest\\Meetingsystem\\meeting.mdb");
    $rs = $conn->Execute("SELECT Time, Meeting, Room, Date FROM Event WHERE Date Like '%" .date("n/d/Y"). "%' ORDER BY Time");
    while (!$rs->EOF)
    {
        $time = strtotime($rs->Fields('Date') . ' ' . $rs->Fields('Time')); 
        $timedisp = strtotime($rs->Fields("Time")->Value);
        if($time>time())
        {
            $meetings[$count] = array("Time"=> date("H:i",$timedisp),
                                      "Meeting"=>$rs->Fields("Meeting")->Value,
                                      "Room"=>$rs->Fields("Room")->Value);
            $count = $count + 1;
            $maxList = $maxList + 1;
            if($maxList == 9)
            {
                $pageTotal = $pageTotal + 1;
                $maxList=1;
            }
        }
        $rs->MoveNext();
    }
    
    $_SESSION["total_pages"] = $pageTotal*2;
    
    $i = 1;
    $y = 0;
    while($y < ($pageTotal*2))
    { 
        if(!empty($meetings))
        {
            while($fillCount < count($meetings) && $countEntries < 9)
            {
                if($i == 1)
                {
                    $i = $i + 1;
                    $content .="<TR bgcolor=#FFFFFF><TD><Font color=black><Center>
                    <font size=4 face=Arial>".$meetings[$fillCount]["Time"].
                    "</TD><TD><Font color=black size=4 face=Arial>&nbsp;"
                    .$meetings[$fillCount]["Meeting"]."</TD><TD>
                    <Font color=black size=4 face=Arial>".$meetings[$fillCount]["Room"]."</TD</TR>";
                }
                else
                {
                    $i = $i - 1;
                    $content .="<TR bgcolor=#3E797D><TD><Font color=black><Center>
                    <font size=4 face=Arial>".date("H:i",$meetings[$fillCount]["Time"]).
                    "</TD><TD><Font color=black size=4 face=Arial>&nbsp;"
                    .$meetings[$fillCount]["Meeting"]."</TD><TD>
                    <Font color=black size=4 face=Arial>".$meetings[$fillCount]["Room"]."</TD</TR>";
                }
                $fillCount = $fillCount + 1;
                $countEntries = $countEntries + 1;
            }
        }
        for($x = $countEntries; $x <= 9; $x++)
        {
            if($i==1)
            {
                $i = $i + 1;
                $content .= "<TR bgcolor=#FFFFFF><TD><Font color=black><Center>
                <Font size=4 face=Arial>&nbsp;
                </TD><TD><Font color=black size=4 face=Arial>&nbsp;</TD><TD>
                <Font color=black size=4 face=Arial>&nbsp;</TD</TR>";
            }
            else
            {
                $i=$i-1;
                $content .= "<TR bgcolor=#3E797D><TD><Font color=black><Center>
                <Font size=4 face=Arial>&nbsp;
                </TD><TD><Font color=black size=4 face=Arial>&nbsp;</TD><TD>
                <Font color=black size=4 face=Arial>&nbsp;</TD</TR>";
            }
        }
        $countEntries = 0;
        $all[$y] = $content;
        $content = "";
        $y =$y + 1;
        
    }
    
    $_SESSION["all_meetings"] = $all;
    $_GET["page"] = 0;
?>
    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset= iso-8859-1">
    <title>Meeting Display System</title>
    </head>
    <body background="background.jpg" text="#006699" link="#0000ff" vlink="#ff00ff" rightmargin=0>
    <BR>
    <TABLE>
    <TR><TD width=100 valign=top><CENTER><IMG height=65 src="cummings3.jpg" width=75 ></CENTER></TD>
    <TD width=320><CENTER><FONT face="Book Antiqua" color="#F3F49C" size = 6><I>
    Maison Cummings House</I></FONT></CENTER></TD><TD><CENTER>
    <FONT face="Book Antiqua" color="#F3F49C" size=3><?php echo date("l, F d, Y"); ?></FONT><BR>
    <FONT face="Book Antiqua" color="#F3F49C" size=5><CENTER><?php echo date("h:i A"); ?></CENTER></FONT></CENTER></TD></TR></TABLE>
    <TABLE border= 1 bordercolor=black><TR><TD><center>
    <font size=5.5 color=black><B><U>Time</B></font></center></U></TD><td width=500>
    <center><font size=5 color=black><B><U>Meeting</B></font></center></U></td>
    <TD width=200><font size=5 color=black><B><U>Room</B></font><CENTER></CENTER></U></TD></TR>
<?php
 
if($_GET["page"] < $_SESSION["total_pages"])
{
     echo '<script>window.onload = function()
        {
        setTimeout("window.location = \''.htmlentities($_SERVER['PHP_SELF']).'?page='.($_GET['page']+1).'\'", 6000);
        }</script>';
}
else
{
 echo '<script>window.onload = function()
{
setTimeout("window.location = \''.htmlentities($_SERVER['PHP_SELF']).'?page='.($_GET['page']).'\'", 6000);
}</script>';
$_GET["page"]++;
}
        
echo $_SESSION["all_meetings"][$_GET["page"]];
 ?>
</table></body></html>
Everything works fine, exept when the page reloads it reaches to the end, which is the number of total pages, but it doesn't go back to the first page to start the cycle again...
Anyone can see the problem?
Post Reply