php案頭中心(四) 資料顯示
來源:互聯網
上載者:User
最後一步就是顯示了。
下面這個程式要通過參數來調用。
比如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>
<?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> <?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>