首先看看代码:
common.php
<?php
$dbhost="localhost";
$dbuser=" 数据库的用户名";
$dbpass=" 数据库的密码";
$dbname=" 数据库的名称";
$table="news"; //数据库的表名
$link=@mysql_connect($dbhost,$dbuser,$dbpass); //连接数据库
if(!$link) //检查连接是否正常
{
print"&newsText=".urlencode("could not connect to server!");
exit;
}
if(!@mysql_select_db($dbname))
{
print"&newsText=".urlencode("could not select $dbname database!");
exit;
}
?>
fetchnews.php
<?php
include'common.php'; //把common.php文件包含进来
$page=$_POST['page']*5;
$query="select * from news order by newsID limit $page,5"; //数据库语句,表示以newsID为键,显示从第$page条开始的五个信息
$result=@mysql_query($query); //检查查询是否没有问题
if($result&&@mysql_num_rows($result)>0)
{
$newsText=""; //初始化变量newsText,有待传进FLASH中
while($row=mysql_fetch_array($result)) //以循环方式把数据一组组输出
{
$posted=strftime("%H:%M",$row['posted']);
$newsText.=stripslashes($row['bt']);
$newsText.='<br>';
$newsText.='<font size="10">';
$newsText.=$posted."by".$row['author'];
$newsText.='</font><br>';
$newsText.=stripslashes($row['body']);
$newsText.='<br><br>';
}
print "&newsText=".urlencode($newsText);
}
else
{
print "&newsText=".urlencode("No news items yet"); //如果没有数据,则显示出Nonews items yet
}
mysql_close($link); //关闭数据库
?>
这就是php部分的代码,从而省略了updown.php这一段代码,本fetchnews.php代码修改了两个地方,第一个地方是把 print"&page=0";改为了 $page=$_POST['page']*5;第二是把 $query="select * from news order by newsID limit 0,5";改为了 $query="select * from news order by newsID limit $page,5";讲讲原理:就是把本来在php中赋初值的变量$page,改为在flash中赋初值,值得注意的是,应该把$page设置为局部的变量,即在定义变量的时候在前面加上var,这样就可以实现换页,并且不用多一个php文件.由于php文件的变动,flash部分自然也要相对的改变,在该影片剪辑中,建立一个新图层,命名为as专门来放置AS代码.在该层的,第一帧修改为以下代码:
System.useCodepage=true;
newsText="";
var page=0;
loadVariables("fetchnews.php?"+(Math.random()*1000000),this,"POST");//以POST形式使用fetchnews.php中的数据
stop();
common.php
<?php
$dbhost="localhost";
$dbuser=" 数据库的用户名";
$dbpass=" 数据库的密码";
$dbname=" 数据库的名称";
$table="news"; //数据库的表名
$link=@mysql_connect($dbhost,$dbuser,$dbpass); //连接数据库
if(!$link) //检查连接是否正常
{
print"&newsText=".urlencode("could not connect to server!");
exit;
}
if(!@mysql_select_db($dbname))
{
print"&newsText=".urlencode("could not select $dbname database!");
exit;
}
?>
fetchnews.php
<?php
include'common.php'; //把common.php文件包含进来
$page=$_POST['page']*5;
$query="select * from news order by newsID limit $page,5"; //数据库语句,表示以newsID为键,显示从第$page条开始的五个信息
$result=@mysql_query($query); //检查查询是否没有问题
if($result&&@mysql_num_rows($result)>0)
{
$newsText=""; //初始化变量newsText,有待传进FLASH中
while($row=mysql_fetch_array($result)) //以循环方式把数据一组组输出
{
$posted=strftime("%H:%M",$row['posted']);
$newsText.=stripslashes($row['bt']);
$newsText.='<br>';
$newsText.='<font size="10">';
$newsText.=$posted."by".$row['author'];
$newsText.='</font><br>';
$newsText.=stripslashes($row['body']);
$newsText.='<br><br>';
}
print "&newsText=".urlencode($newsText);
}
else
{
print "&newsText=".urlencode("No news items yet"); //如果没有数据,则显示出Nonews items yet
}
mysql_close($link); //关闭数据库
?>
这就是php部分的代码,从而省略了updown.php这一段代码,本fetchnews.php代码修改了两个地方,第一个地方是把 print"&page=0";改为了 $page=$_POST['page']*5;第二是把 $query="select * from news order by newsID limit 0,5";改为了 $query="select * from news order by newsID limit $page,5";讲讲原理:就是把本来在php中赋初值的变量$page,改为在flash中赋初值,值得注意的是,应该把$page设置为局部的变量,即在定义变量的时候在前面加上var,这样就可以实现换页,并且不用多一个php文件.由于php文件的变动,flash部分自然也要相对的改变,在该影片剪辑中,建立一个新图层,命名为as专门来放置AS代码.在该层的,第一帧修改为以下代码:
System.useCodepage=true;
newsText="";
var page=0;
loadVariables("fetchnews.php?"+(Math.random()*1000000),this,"POST");//以POST形式使用fetchnews.php中的数据
stop();
转载于:https://blog.51cto.com/songcz/153961