Jump to content

Recommended Posts

I have a php page that is made up of three pieces.

header.php

main.php

footer.php

 

I only want the header.php part to refresh every 60 seconds as it has a scoreboard that pulls data out of mysql.

The main area has multiple things that could be going on and can't be refreshed unless the user clicks a button or link to another page.

So using meta refresh won't work as it see's all three pieces as one page and refreshes everything as does a bunch of other things I have tried.

 

Anyone have an example of how I can do this in ajax?

 

Thanks

 

Hits

Link to comment
https://forums.phpfreaks.com/topic/214132-ajax-to-refresh-only-headerphp/
Share on other sites

This is very possible.. I do it all the time.  I have a game with a chat screen and in the side bar is a window with the  player's statistics.  I update the chat every 10 seconds and the stats every 60 seconds.  Got some code for us to work with?

Here is the header.php

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<meta name="author" CONTENT="Jason Goetz">
<meta name="publisher" CONTENT="Jason Goetz">
<meta name="keywords" content="phpffl, php, mysql, web based fantasy football, fantasy football, nfl fantasy football, php fantasy football, php nfl fantasy football, free fantasy football, free nfl fantasy football, open source, open source fantasy football, open source php fantasy football, nfl, free fantasy american football, free fantasy football league manager, free fantasy football league, fantasy football league manager, custom fantasy football, customizable fantasy football, online fantasy football, free online fantasy football. fantasy football forum, fantasy football forums, fantasy football message board, fantasy football message boards, fantasy football bulletin boards, sourceforge fantasy football, sourceforge php mysql, sourceforge free fantasy football">
<meta name="description" content="phpFFL is a free, open-source and fully customizable online Fantasy Football League Manager with automatic live scoring. Everything in phpFFL, from league adminstration to individual team player transactions and lineup submissions is handled through an easy to use online interface. phpFFL is easy to install and you can have your league up and running very quickly. phpFFL is written in php and uses a MySQL database so the only requirements are that your server supports php and MySQL.">
<title>phpFFL : Enzone Fantasy Football League Manager</title>
<!--<link rel="shortcut icon" href="./favicon.ico" />-->
<link href="css/thickbox.css" rel="stylesheet" type="text/css">
<link href="<?php echo $PHPFFL_WEB_ROOT;?>css/main.css" rel="stylesheet" type="text/css">
<script language="javascript" src="<?php echo $PHPFFL_WEB_ROOT;?>js/writelayer.js"></script>
<script language="javascript" src="<?php echo $PHPFFL_WEB_ROOT;?>js/jquery-1.3.2.js"></script>
<script language="javascript" src="<?php echo $PHPFFL_WEB_ROOT;?>js/thickbox.js"></script>

<script type="text/javascript">

function reStripeTables(){
    $(".stripeMe tr:even").removeClass("alt");
    $(".stripeMe tr:even").addClass("alt");

    $(".stripeMe tr").mouseover(function(){
        $(this).addClass("over");
    });
    $(".stripeMe tr").mouseout(function(){
        $(this).removeClass("over");
    });
}
$(document).ready(function() {
    reStripeTables();
});
</script>
</head>
<body <?php echo $BODY_TAG_TEXT;?>>

<table class="bodyline" width="100%" cellspacing="0" cellpadding="0" border="0">
  <tr><td>
<table class="" width="100%" cellspacing="0" cellpadding="0" border="0">
    <tr>
        <td>
            <table width="100%" cellspacing="0" cellpadding="0" border="0">
                <tr><?php
                    $MAIN_PHPFFL_LOGO=$PHPFFL_IMAGE_PATH."phpffl_280.jpg";
                    if(strlen($LEAGUEID)>0)
                    {
                        $sql="select league_logo from leagues where ID=$LEAGUEID;";
                        $leagues_rs=$DB->Execute($sql);
                        if(!($leagues_rs->EOF))
                        {
                            $current_league_logo=$leagues_rs->fields("league_logo");
                            if(is_file($PHPFFL_FILE_ROOT."images/team_logos/$current_league_logo"))
                            {
                                $MAIN_PHPFFL_LOGO=$PHPFFL_IMAGE_PATH."/team_logos/{$current_league_logo}";
                            }
                        }
                    } 
                    $week=$_REQUEST['Week'];                   
               ?> 
               <td align="left" width="25%"><img src="<?php echo $MAIN_PHPFFL_LOGO;?>" border="0" alt="phpFFL Home" title="phpFFL Home" /> 
               </td> 
               <td align="center" valign="top" width="50%">    
                  <div id="Logged_In_Display" class="Logged_In_Display"><?php get_top_scoring_teams(); ?></div><br /> <!---->
               </td> 
               <td align="right" valign="bottom" width="25%"><div id="Logged_In_Display" class="Logged_In_Display"><?php echo "$Logged_In_Display";?></div> 
               </td> 
            </tr> 

            <!--<tr class="topbkg">-->
               <td height="11" colspan="2">
               
</td>
                </tr>
            </table>                       
        </td>
    </tr>
    
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="2">
    <tr>
        <td align="center" class="topnav"> 
        <?php
        if(strlen($USERSID)<1)
        {?>
            <a href="signup.php"><?php echo SIGN_UP;?></a>  &#8226;  
            <a href="login.php"><?php echo LOGIN;?></a>  &#8226;  
        <?php
        }
        else
        {
            $user_in_league=is_user_in_league($USERSID, $LEAGUEID);
        ?>
            <a href="logout.php"><?php echo LOGOUT;?></a>  &#8226;  
        <?php
            if($user_in_league==1)
            {
        ?>
                <a href="my_team.php"><?php echo MY_TEAM;?></a>  &#8226;  
        <?php
            }
        }
        ?>
        <?php
        if(strlen($LEAGUEID)>0)
        {
        ?>

            <a href="statistics.php"><?php echo STATISTICS;?></a>  &#8226;  
            <a href="transactions.php"><?php echo TRANSACTIONS;?></a> &#8226; 
            <a href="custom_pages.php"><?php echo CUSTOM_PAGES;?></a>  &#8226; 
            <a href="statistics.php?Mode=live_scoring&Action=live_scoring_main"><?php echo Live_Scoring;?></a> &#8226; 
        <?php
        }
        ?>
<a href="leagues.php"><?php echo LEAGUES;?></a>  &#8226;  
<?php
if($ISADMIN==1)
{
?>
<a href="admin.php"><?php echo ADMIN;?></a>  &#8226;  
<?php
}
?>
<?php
if(strlen($USERSID>0))
{
?>
<a href="profile.php"><?php echo PROFILE;?></a>  &#8226;  
<?php
}
?>
<a href="faq.php"><?php echo FAQ;?></a></td>
    </tr>
</table>
<div style="position:absolute; top:150px; left:50%; margin-left:-400px; width:800px; height:50px; font-size:16px; color:blue; font-family:ARIAL;"><marquee direction="LEFT" width="100%" scrollamount="2">Waiver Order----1. Jeff   2. Curt   3. Tim H   4. Rita   5. Bob   6. Tim A   7. Tom   8. Scott   9. John   10. Bill -------Waivers will be processed Thursday night at 10:00pm this week.</marquee></div>
<!--  Start of Nfl ScoreBoard  -->
<div align="center">
<table class="scores_bar" cellspacing="0" cellpadding="0">
                    <tr>
                        <td>
            <?php
                $week = $_REQUEST['Week'];
                $year = $_REQUEST['Year'];
                //echo $week;
                if($year=="")
                {
                    $year = get_current_number_year();
                }
                if ($week < 1 && strpos($year,"POST")>0)
                {
                    $week = 3;
                }
                elseif ($week < 1)
                {
                    $week = get_current_week(-28);
                }
                if ($week < 1)
                {
                    $week = 1;
                    $year = get_current_number_year();
                    $year=$year-1;
                }
                //echo $year;
                echo "<li>Week $week</li>";
                echo "<ul  class='nfl-scores'>";
                echo "<br />";
                                echo "<br />";
            $sql="select ID, seasonID, kickoff, week, status, awayscore, homescore, game_date from league_schedules where week='$week' and seasonid='$year';";
            //echo $sql;
            $rs=$DB->Execute($sql);
            if($rs)
            {
                $count=0;
                while(!($rs->EOF))
                {

                    echo "<li>";
                    //$LEAGUEID=$rs->fields("ID");
                    $gameid = $rs->fields("ID");
                    $game = substr($gameid,strpos($gameid,"_")+1,strlen($gameid));
                    $away = substr($game,0,strpos($game,"@"));
                    $home = substr($game,strpos($game,"@")+1,strlen($game));
                    $status = $rs->fields("status");
                    
                    if($status == "Scheduled")
                    {
                        $tempdate = explode("-",$rs->fields("game_date"));
                        $time = substr($tempdate[2],strpos($tempdate[2]," ")+1);
                        $hour = substr($time,0,strpos($time,":"));
                        $min = substr($time,3,2);
                        $month = $tempdate[1];
                        $day = substr($tempdate[2],0,strpos($tempdate[2]," "));
                        $year = $tempdate[0];
                        //echo "$hour - $min";
                        $info = date("D n/j g:i",mktime($hour,$min,0,$month,$day,$year));
                    }
                    else
                    {
                        $info = $status;
                    }
                    if(intval($rs->fields("homescore")) > intval($rs->fields("awayscore")))
                    {
                        echo "<a href = 'http://www.sportsline.com/nfl/gamecenter/live/NFL_".$rs->fields("ID")."' target='_blank'>".$rs->fields("year")."";
                        echo "<span class='losing_team'>".$rs->fields("awayscore")." ".$away."</span><br><span class='winning_team'>".$rs->fields("homescore")." ".$home."</span><BR>".$info."</a>";
                    }
                    elseif(intval($rs->fields("'homescore")) < intval($rs->fields("awayscore")))
                    {
                            echo "<a href = 'http://www.sportsline.com/nfl/gamecenter/live/NFL_".$rs->fields("ID")."' target='_blank'>".$rs->fields("year")."";
                        echo "<span class='winning_team'>".$rs->fields("awayscore")." ".$away."</span><br><span class='losing_team'>".$rs->fields("homescore")." ".$home."</span><BR>".$info."</a>";
                    }
                    else
                    {
                        echo "<a href = 'http://www.sportsline.com/nfl/gamecenter/live/NFL_".$rs->fields("ID")."' target='_blank'>".$rs->fields("year")."";
                        echo "<span class='losing_team'>".$rs->fields("awayscore")." ".$away."</span><BR><span class='losing_team'>".$rs->fields("homescore")." ".$home."</span><BR><span class='winning_team'>".$info."</span></a>";
                    }
                    echo "</li>";
                    $count++;
                    $rs->movenext();
                    
                }
         }
        echo "</ul></td>";

    ?>
        
                    </tr>
                </table>
                </div>
<!--  End of Nfl ScoreBoard  -->
<table style="width: 95%;" border="0" cellspacing="5" cellpadding="5">
<tr>
<td style="vertical-align: top; width: 100%;">
<div align="center">
<?php get_top_scoring_player(); ?></div>

 

The main part  one of many depending what they are doing.

Here is one that shows the users team data.

 

<?php
include("program_files/config.php");
include("program_files/myteam/functions/myteam_home_functions.php");
include("program_files/myteam/functions/starting_lineup_functions.php");
include("program_files/myteam/functions/waiver_wire_functions.php");
include("program_files/myteam/functions/trades_functions.php");
include("program_files/myteam/functions/team_correspondance_functions.php");
include("program_files/myteam/functions/draft_functions.php");
include("program_files/myteam/functions/private_message_functions.php");
include("program_files/statistics/functions/teams_functions.php");
include("program_files/statistics/functions/players_functions.php");
include("program_files/statistics/functions/schedules_functions.php");
include("program_files/statistics/functions/scoring_functions.php");
include("program_files/statistics/functions/live_scoring_functions.php");
include("language/{$PHPFFL_DEFAULT_LANGUAGE_DIR}/my_team.php");


$Mode=$_REQUEST['Mode'];
$Printable=$_REQUEST['Printable'];

if(strlen($USERSID)<1 || strlen($LEAGUEID)<1)
{
    session_write_close();
    header("Location: {$PHPFFL_WEB_ROOT}leagues.php?PHPSESSID=$PHPSESSID");
    exit();
}
$sql="select teams_ID from users_teams, teams where users_ID=$USERSID and teams_ID=teams.ID and leagues_ID=$LEAGUEID;";
$rs=$DB->Execute($sql);
if(!($rs->EOF))
{
    $Teams_ID=$rs->fields("teams_ID");
    $Teamname=get_team_name($Teams_ID);
}
if(strlen($Teams_ID)<1)
{
    session_write_close();
    header("Location: {$PHPFFL_WEB_ROOT}statistics.php?PHPSESSID=$PHPSESSID");
    exit();
}
Switch($Mode)
{
    default:
        case "myteam":
        $Mode="myteam";
        $File_To_Include="program_files/myteam/myteam_home.php";
        $Page_Title="$Teamname";
    break;    
    case "starting_lineup":
        $File_To_Include="program_files/myteam/starting_lineup.php";
        $Page_Title=STARTING_LINEUP;
    break;
case "live_scoring":
        $File_To_Include="program_files/statistics/live_scoring.php";
        $Page_Title=LIVE_SCORING;
        //$Meta_Refresh="<meta http-equiv=\"refresh\" content=\"120\">";
    break;
    case "waiver_wire":
        $File_To_Include="program_files/myteam/waiver_wire.php";
        $Page_Title=WAIVER_WIRE;
    break;
    case "trades":
        $File_To_Include="program_files/myteam/trades.php";
        $Page_Title=TRADES;
    break;
    case "team_correspondance":
        $File_To_Include="program_files/myteam/team_correspondance.php";
        $Page_Title=CORRESPONDANCE;
    break;
    case "STATISTICSBENCH":
    $File_To_Include="statisticsbench.php";
    $Page_Title=STATISTICSBENCH;
    break;    
    case "draft":
        $File_To_Include="program_files/myteam/draft.php";
        $Page_Title=DRAFT;
    break;
    case "private_message":
        $File_To_Include="program_files/myteam/private_message.php";
        $Page_Title=PRIVATE_MESSAGES;
    break;    
}
$Logged_In_Display=get_users_display($USERSID);
if($Printable)
{
    include("template/printable_header.php");
}
elseif($IsAjax)
{
    //No Header
}
else
{
    include("template/header.php");
}
$league_name=get_league_name($LEAGUEID);
$Page_Title=$league_name.": ".$Page_Title;
if(!($Printable) && !($IsAjax))
{
    include("template/myteam_leftnav.php");
}
include($File_To_Include);
if(!($Printable) && !($IsAjax))
{
    echo "</td></tr></table></td></tr></tbody></table>";
}
if($Printable)
{
    include("template/printable_footer.php");
}
elseif($IsAjax)
{
    //No Footer
}
else
{
    include("template/footer.php");
}
?>

 

Then the footer is

<?php

/*Modified by BOCTOK - 13 Oct 2007
*to enable "Who's Online" functionality
*/

$timestamp = time();
$previous = "300"; //Time in seconds (5 minutes)
$timeout = $timestamp-$previous;

if(isset($_SESSION['USERSID'])) 
{
$users_ID=$_SESSION['USERSID'];
}
else
{
$users_ID = 'none';
}
if (!($users_ID == 'none'))
{

//Get the username
$sql="SELECT username FROM users WHERE ID='$users_ID'";
$rs=$DB->Execute($sql);    // Iterate through results
$Username = $rs->fields("username");

//See if username is in the active_users table
$sql="SELECT username FROM active_users WHERE username='$Username'";
$rs=$DB->Execute($sql);
$active_user = $rs->fields("username");

//Update or insert user into active_users depending on the result
                    if ($active_user =='')
                    {
                    $sql="INSERT INTO active_users (username, timestamp) VALUES ('$Username', '$timestamp');";
                    $rs=$DB->Execute($sql);
                    }
                    else
                    {
                    $sql="UPDATE active_users SET timestamp='$timestamp' WHERE username='$Username';";
                    $rs=$DB->Execute($sql);
                    }
}

//Delete inactive users after 5 minutes
$sql="DELETE FROM active_users WHERE timestamp < '$timeout'";
$rs=$DB->Execute($sql);

//Query to get total number of members
$sql="SELECT * FROM users";
$rs=$DB->CacheExecute(600,$sql);
$num_members=$rs->RecordCount();

//Query to get total number of leagues
$sql="SELECT * FROM leagues";
$rs=$DB->CacheExecute(600,$sql);
$num_leagues=$rs->RecordCount();

//Display member - league totals
echo "</td></tr><tr><td align=\"center\"><br><br>";
echo "<b>Member Total: There are ".$num_members. " </b><br>";
if($num_leagues == '1')
{
echo "<b>members in ".$num_leagues. " league.</b>";
}
else
{
echo "<b>members in ".$num_leagues. " leagues.</b><br>";
}
echo "<br>";

//Find out how many members are online
$sql="SELECT * FROM active_users";
$rs=$DB->Execute($sql);
$num_active_users=$rs->RecordCount();

//Account for good grammar 
if($num_active_users == '1')
{
echo "There is $num_active_users member online.";
echo "<br>";
}
else
{
echo "There are $num_active_users members online.";
echo "<br>";
}


echo "<table style='width: 100%;' ><tr><td style='vertical-align: bottom; width: 25%; text-align: center;' class='subtitle' ><font size='2'><b>Who is online?</b></font><br>";

//Get member names of who is online
$sql = "SELECT username FROM active_users ORDER BY timestamp DESC,username";
$rs=$DB->GetCol($sql);

if($rs == '0')
        {
           echo "<table align=\"center\" border=\"0\" cellspacing=\"2\" cellpadding=\"3\">\n";
           echo "<font size=\"2\" color = \"red\">No Users Online!";
           echo "</font></td></tr></table><br><br><br>\n";
        }
else  
        {
            echo "<table align=\"center\" border=\"1\" cellspacing=\"2\" cellpadding=\"3\">\n";
           echo "<tr><td><font size=\"2\">\n";
           echo (join(", ", $rs));
        }
echo "</td></tr></table>";
?>


<table style="width: 100%;" ><tr><td style="vertical-align: bottom; width: 25%; text-align: center;" class="subtitle" > </td><td style="vertical-align: bottom; width: 75%; text-align: center;" class="subtitle" ><a href="http://www.phpffl.com" target="_blank"><img src="<?php echo "$PHPFFL_IMAGE_PATH";?>phpFFL_sml.jpg" alt="phpFFL Home Page"></a>  <a href="http://sourceforge.net/projects/phpffl/" target="_blank"><img src="<?php echo "$PHPFFL_IMAGE_PATH";?>sourceforge_logo.bmp" alt="phpFFL Sourceforge Project"></a><br><br><span class="table_data_large"><?php echo POWERED_BY_PHPFFL;?> <?php echo $PHPFFL_CURRENT_VERSION;?> - © <?php echo date("Y"); ?> phpFFL, Inc.</span></td></tr></table>
</body>
</html>

 

Thanks for any advice you can give me on this.

 

Hits

 

 

 

I need to do something like this but I don't know where to begin

 

wrap the header.php in a div with an id, say headerDiv

 

Then  use javascript setTimeout to call a function every 60 seconds.

 

and that function would call a jquery get on header.php, although header.php likely doesn't have access to config so i might actually need to make a separate file headerAjax.php. and add  Include config.php at the top, then include header.php

 

then call the jquery ajax call and populate the div with the results.

 

Thanks

Hits

  • 2 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.