首页 > 开发 > PHP > 正文

桌面中心(四) 数据显示

2024-05-04 23:01:59
字体:
来源:转载
供稿:网友
最后一步就是显示了。
下面这个程序要通过参数来调用。
比如php.php?jpg=jpg
后面的jpg是表格名。记住一定要的呀,不然就不能运行了,会显示程序出错。
大家可以把下面这个程序改一下。这样就可以更加美观了。

以下是源程序:
<html>
<head><title>显示</title>
</head>
<body>
<?
mysql_connect("localhost","用户名","密码") or die("无法联接数据库!");
$query="select id,url,mess,fromx,url1,mess1,fromx1,url2,mess2,fromx2,url3,mess3,fromx3 from $jpg " ;
$result=mysql_db_query("elong",$query); //执行查询
$num=mysql_numrows($result);
$page=round($page);
$pagesize=4;
if ($page==0){
$page=1;}
else{
$page=$page;}
$pagecount=($num)/$pagesize;
$pagecount=ceil($pagecount);
?>
<?if ($page!=1 and $num!=0){
printf("<a href="%s?page=%s&jpg=$jpg">首页</a>",$php_self,1);
printf("<a href="%s?page=%s&jpg=$jpg"> 前页</a>",$php_self,$page-1);
}else{
?> 首页 前页 <?
}
?>
</font>&nbsp;
<?if ($page!=$pagecount and $num!=0){
printf("<a href="%s?page=%s&jpg=$jpg"> 后页</a>",$php_self,$page+1);
printf("<a href="%s?page=%s&jpg=$jpg"> 尾页</a>",$php_self,$pagecount);
}else{?> 后页 尾页 <?}?>页次:<strong><?echo $page?></strong>/<strong><?echo $pagecount?></strong>页
</span></td>
<?
if ($num<>0){
$pp=0;
for($ipage=0;$ipage<$pagesize;$ipage++){
$i=($page-1)*$pagesize+$ipage;
if($i < $num) {
$id=mysql_result($result,$i,"id");
$url=mysql_result($result,$i,"url");
$mess=mysql_result($result,$i,"mess");
$fromx=mysql_result($result,$i,"fromx");
$url1=mysql_result($result,$i,"url1");
$mess1=mysql_result($result,$i,"mess1");
$fromx1=mysql_result($result,$i,"fromx1");
$url2=mysql_result($result,$i,"url2");
$mess2=mysql_result($result,$i,"mess2");
$fromx2=mysql_result($result,$i,"fromx2");
$url3=mysql_result($result,$i,"url3");
$mess3=mysql_result($result,$i,"mess3");
$fromx3=mysql_result($result,$i,"fromx3");
$pp=$pp+1;
       ?>
<table width="668" border="2" cellspacing="0" cellpadding="0" align="center" bordercolor="#ffffff">
<tr>
<td width="167" height="127"> <a href="<?echo $url?>" target="_blank"><img border=0 src="<?echo $mess?>" width="160" height="120" border="4"></td>
<td width="167" height="127"><a href="<?echo $url1?>" target="_blank"><img border=0 src="<?echo $mess1?>" width="160" height="120" border="4"></td>
<td width="167" height="127"><a href="<?echo $url2?>" target="_blank"><img border=0 src="<?echo $mess2?>" width="160" height="120" border="4"></td>
<td width="167" height="127"><a href="<?echo $url3?>" target="_blank"><img border=0 src="<?echo $mess3?>" width="160" height="120" border="4"></td>
</tr>
</table>

<?
}
}
}
?>

  <td nowrap align=center> <span class=smallfont><span class=titlefont>分页</span>
     <font color=darkgray> <?if ($page!=1 and $num!=0){
printf("<a href="%s?page=%s&jpg=$jpg">首页</a>",$php_self,1);
printf("<a href="%s?page=%s&jpg=$jpg"> 前页</a>",$php_self,$page-1);
}else{
?> 首页 前页 <?}?> </font>&nbsp;<?if ($page!=$pagecount and $num!=0){
printf("<a href="%s?page=%s&jpg=$jpg"> 后页</a>",$php_self,$page+1);
printf("<a href="%s?page=%s&jpg=$jpg"> 尾页</a>",$php_self,$pagecount);
}else{?> 后页 尾页 <?}?>页次:<strong><?echo $page?></strong>/<strong><?echo $pagecount?></strong>页
</span></td>

 </table></div></center>
</body></html>

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表