在php上询问自动刷新div [英] Ask about auto refresh div at php

查看:58
本文介绍了在php上询问自动刷新div的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我需要你的帮助。我想建立一个日历议程。我找到了一个脚本并修改了包含数据库功能。

这是 calendar.php

Hi All,

I need your help. I want to build a calendar agenda. I''ve found a script and modified for include database function.
This is calendar.php

<?php
include "connection.php";
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Agenda</title>
</head>
<body>
 
<?php
$monthNames = Array("January", "February", "March", "April", "May", "June", "July",
"August", "September", "October", "November", "December");
?>
<?php
if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");
?>
<?php
$cMonth = $_REQUEST["month"];
$cYear = $_REQUEST["year"];
$prev_year = $cYear;
$next_year = $cYear;
$prev_month = $cMonth-1;
$next_month = $cMonth+1;
if ($prev_month == 0 ) 
{
	$prev_month = 12;
	$prev_year = $cYear - 1;
}
if ($next_month == 13 ) 
{
	$next_month = 1;
	$next_year = $cYear + 1;
}
?>
<table width="200">
<tr align="center">
<td bgcolor="#999999" style="color:#FFFFFF">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="50%" align="left"><a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $prev_month . "&year=" . $prev_year; ?>" style="color:#FFFFFF">Previous</a></td>
<td width="50%" align="right"><a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $next_month . "&year=" . $next_year; ?>" style="color:#FFFFFF">Next</a></td>
</tr>
</table>
</td>
</tr>
</table>
<tr>
<td align="center">
<table width="100%" border="0" cellpadding="2" cellspacing="2">
<tr align="center">
<td colspan="7" bgcolor="#999999" style="color:#FFFFFF"><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></td>
</tr>
<tr>
<td align="center" bgcolor="#999999" style="color:#FFFFFF">S</td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF">M</td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF">T</td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF">W</td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF">T</td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF">F</td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF">S</td>
</tr>
<?php
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];
for ($i=0; $i<($maxday+$startday); $i++)
{
	if(($i % 7) == 0 )
	{
		echo "";
	}
	if($i < $startday)
	{
		echo "<td></td>\n";
	}else
	{
		$sql = "select * from data_agenda where tgl_agenda='".($i - $startday + 1).'-'.$cMonth.'-'.$cYear."'";
		$hs = mysql_query($sql);
		$jmlAcara = mysql_num_rows($hs);
		echo "<td align='center' valign='middle' height='20px'".($jmlAcara > 0 ? " bgcolor='yellow'" : '').">";
		echo "<a href=2.php?tgl=".urlencode($i - $startday + 1)."  önclick=\"window.open(this.href,'window','width=640,height=480,resizable,scrollbars,toolbar,menubar') ;return false;\">".($i - $startday + 1)."</a><br>";
 
		echo "</td>\n";
	}
	if(($i % 7) == 6 )
	{
		echo "</tr>\n";
	}
}
?>





做了一些评论后,我遇到了问题。当用户A插入新议程时,用户B必须手动刷新以查看更改。所以我正在使用自动刷新div ajax并将上面的代码分成两部分。第一个是日历,第二个是数据库。但是日期没有正确显示有一些错误。

这里的日历代码分为两部分。

cal .php



After doing some review, I''ve got a problem. When user A insert new agenda, user B must refresh it manually to see the changes. So I''m using auto refresh div ajax and split the code above into two parts. The first is for calendar and the second is for database. But there''s some error with the date doesn''t show properly.
Here''s the calendar code after divided into two parts.
cal.php

<?php
include "file_koneksi.php";
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
	<script type="text/javascript">
    $(document).ready(function() {
    $.ajaxSetup({ cache: false }); // This part addresses an IE bug. without it, IE will only load the first number and will never 
    setInterval(function() {
    $('#result').load('3.php');
    }, 100); // the "3000" here refers to the time to refresh the div. it is in milliseconds.
    });
</script>
<?php
$monthNames = Array("January","February","March","April","May","June","July","August","September","October","November", "December");
    if (!isset($_REQUEST["month"])) $_REQUEST["month"] = date("n");
    if (!isset($_REQUEST["year"])) $_REQUEST["year"] = date("Y");
    $cMonth = $_REQUEST["month"];
    $cYear = $_REQUEST["year"];
    $prev_year = $cYear;
    $next_year = $cYear;
    $prev_month = $cMonth-1;
    $next_month = $cMonth+1;
    if ($prev_month == 0 ) 
	{
    	$prev_month = 12;
    	$prev_year = $cYear - 1;
    }
    if ($next_month == 13) 
	{
    	$next_month = 1;
    	$next_year = $cYear + 1;
    }
?>
<table width="200">
    <tr align="center">
    <td bgcolor="#999999" style="color:#FFFFFF">
    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td width="50%" align="left"><a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $prev_month . "&year=" . $prev_year; ?>" style="color:#FFFFFF">Previous</a></td>
    <td width="50%" align="right"><a href="<?php echo $_SERVER["PHP_SELF"] . "?month=". $next_month . "&year=" . $next_year; ?>" style="color:#FFFFFF">Next</a></td>
    </tr>
    </table>
    </td>
    </tr>
	</table>

<table width="100%" border="1" cellpadding="2" cellspacing="2">
<tr align="center">
<td colspan="7" bgcolor="#999999" style="color:#FFFFFF"><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></td>
</tr>
<tr>
<td align="center" bgcolor="#999999" style="color:#FFFFFF">S</td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF">M</td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF">T</td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF">W</td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF">T</td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF">F</td>
<td align="center" bgcolor="#999999" style="color:#FFFFFF">S</td>
</tr>
</table>
<div id="result">
</table>
</td>
</tr>
</table>





And here’’s the database code

3.php



And here''s the database code
3.php

include "file_koneksi.php";
echo"<table>";
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];

for ($i=0; $i<($maxday+$startday); $i++) 
{
	//echo "($maxday+$startday)";	
	//echo "<a href=2.php>".$i."</a><br>";
	if(($i % 7) == 0 ) 
	{
		echo "";
    }
	if($i < $startday) 
	{
		echo "<td></td>\n";

    }else 
	{
		$sql = "select * from data_agenda where tgl_agenda='".($i - $startday + 1).'-'.$cMonth.'-'.$cYear."'";
		$hs = mysql_query($sql);
		$jmlAcara = mysql_num_rows($hs);
		echo "<td align='center' valign='middle' height='20px'".($jmlAcara > 0 ? " bgcolor='yellow'" : '').">";
		echo "<a href=2.php?tgl=".urlencode($i - $startday + 1)."&month=".urlencode($monthNames[$cMonth-1])."  önclick=\"window.open(this.href,'window','width=640,height=480,resizable,scrollbars,toolbar,menubar') ;return false;\">".($i - $startday + 1)."</a><br>";
		echo "</td>\n";
		//echo "$cMonth";
	}
}
?>
</table>





Am I wrong on divided the first script or in put div id ?



Thank you..



Regards,

Ikram



Am I wrong on divided the first script or in put div id ?

Thank you..

Regards,
Ikram

推荐答案

monthNames = Array(\"January\", \"February\", \"March\", \"April\", \"May\", \"June\", \"July\",
\"August\", \"September\", \"October\", \"November\", \"December\");
?>
<?php
if (!isset(
monthNames = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); ?> <?php if (!isset(


_REQUEST[\"month\"]))
_REQUEST["month"]))


_REQUEST[\"month\"] = date(\"n\");
if (!isset(
_REQUEST["month"] = date("n"); if (!isset(


这篇关于在php上询问自动刷新div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆