데이터베이스 Ajax 스타일의 데이터를 사용하는 코드가 있습니다. 예를 들어, 한 번에 9 번, 더 많이 표시하려면 더 많은 버튼을 누릅니다. 문제는 내가 페이지를 떠날 때 발생합니다. 내가 돌아 왔을 때 뒤로 버튼을 사용할지라도 나는 더 많은 버튼을 다시 눌러서 내가 어디에 있는지를 알아야한다.이 코드 부분에 세션 적용
loadmore.php으로 같은 페이지에 마지막 카운트를
자바 스크립트를 기억하는 세션을 적용하는 방법이 있나요
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
$(function()
{
$('.more').live("click",function()
{
var ID = $(this).attr("id");
if(ID)
{
$("#more"+ID).html('<img src="moreajax.gif" />');
$.ajax({
type: "POST",
url: "ajax_more.php",
data: "lastmsg="+ ID,
cache: false,
success: function(html){
$("ol#updates").append(html);
$("#more"+ID).remove(); // removing old more button
}
});
}
else
{
$(".morebox").html('The End');// no results
}
return false;
});
});
</script>
이 주 PHP 스크립트의 loadmore.php
<div id='container'>
<ol class="timeline" id="updates">
<?php
include('config.php');
$sql=mysql_query("select * from messages ORDER BY msg_id DESC LIMIT 9");
while($row=mysql_fetch_array($sql))
{
$msg_id=$row['msg_id'];
$message=$row['message'];
?>
<li>
<?php echo $message; ?>
</li>
<?php } ?>
</ol>
//More Button here $msg_id values is a last message id value.
<div id="more<?php echo $msg_id; ?>" class="morebox">
<a href="#" class="more" id="<?php echo $msg_id; ?>">more</a>
</div>
</div>;
입니다
다음은 ajax_more.php라고하는 PHP입니다
<?php
include("config.php");
if(isSet($_POST['lastmsg']))
{
$lastmsg=$_POST['lastmsg'];
$lastmsg=mysql_real_escape_string($lastmsg);
$result=mysql_query("select * from messages where msg_id<'$lastmsg' order by msg_id desc limit 9");
while($row=mysql_fetch_array($result))
{
$msg_id=$row['msg_id'];
$message=$row['message'];
?>
<li>
<?php echo $message; ?>
</li>
<?php
}
?>
//More Button here $msg_id values is a last message id value.
<div id="more<?php echo $msg_id; ?>" class="morebox">
<a href="#" id="<?php echo $msg_id; ?>" class="more">more</a>
</div>
<?php
}
?>
누구든이 부분에 불이 들어오는 경우. 나는
스티브
ill 고맙습니다;) –
마지막 msgcount가 다른 PHP 페이지에 있기 때문에 ajax_more.php 어떻게 다시 loadmore.php로 호출합니까? –