php桌面中心(四) 数据显示

最后一步就是显示了。 
下面这个程序要通过参数来调用。 
比如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> 

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/c72b24ab398ff85f44b8208f98708fff.html