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>  
<?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> 

<?php
include_once(dirname(__FILE__).’../../Inc/Conn.php’);
include_once(dirname(__FILE__).’../../photo/Inc/function.php’);
?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“;
<html xmlns=”;
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=gb2312″
/>
<title>无标题文档</title>
<style type=”text/css”>
<!–
body,td,th {
 font-size: 12px;
 height:17px;
 padding:8px 0px 0px 0px;
 text-align:center;
 
}
body {
 margin-left: 0px;
 margin-top: 10px;
 margin-right: 0px;
 margin-bottom: 0px;
}
td{
 border:1px solid #333;
 }

–>
</style></head>

<body>
<div style=”height:26px;text-align:left; width:98%;font-size:16px;
font-weight:bold; margin:0px auto;”><a href=”export.php”
target=”_blank”>导出Execel表格</a></div>
<table width=”98%” border=”0″ align=”center” cellpadding=”0″
cellspacing=”0″>
  <tr>
    <td width=”8%”><strong>帐号</strong></td>
    <td width=”14%”><strong>邮箱</strong></td>
    <td width=”5%”><strong>性别</strong></td>
    <td
width=”9%”><strong>宝宝出生日期</strong></td>
    <td width=”12%”><strong>省份</strong></td>
    <td
width=”9%”><strong>真实姓名</strong></td>
    <td width=”12%”><strong>邮编</strong></td>
    <td width=”10%”><strong>手机</strong></td>
    <td width=”21%”><strong>地址</strong></td>
  </tr>
  <?php

    $sql  =”Select * from tablename”;
  
    $result =mysql_query($sql) or die(‘fail1’.mysql_error());
    $rs  =mysql_fetch_array($result);
    $rdcount =mysql_num_rows($result);
    if($rdcount){
    $pagesize =20;
    $pagecount=($rdcount % $pagesize)?(int)($rdcount /
$pagesize)+1:$rdcount/$pagesize;//统计总页面
    $page  =isset($_GET[‘page’])?$_GET[‘page’]:1;//取得当前页面
    $start =($page>=1 &&
$page<=$pagecount)?$start=$pagesize*($page-1):$start=1;//取得超始记录
    $start =$start;
    $sql  =$sql.” order by add_date desc limit $start,$pagesize”;
       
    $result =mysql_query($sql) or die(mysql_error());
  while($rs =mysql_fetch_array($result) ){    
   echo”<tr>
    <td>”.$rs[‘User_Name’].”</td>
    <td>”.$rs[‘User_Mail’].”</td>
    <td>”.$rs[‘User_Baby_Sex’].”</td>
    <td>”.$rs[‘User_Baby_Birth’].” </td>
    <td>”.$rs[‘sheng’].”  </td>
    <td>”.$rs[‘User_rname’].”  </td>
    <td>”.$rs[‘User_Zip’].”  </td>
    <td>”.$rs[‘User_Hand’].”  </td>
    <td>”.$rs[‘User_Address’].”  </td>
     </tr>
     “;
  
  }
  echo “<tr> <td colspan=9>”;
 pagelist1($page,$pagecount,$rdcount,’?page=’,$pagesize);
 echo “</td> </tr> “;
 }else{
   echo ‘暂时没有信息!’;
 }

function pagelist1($page,$pagecount,$totalrecord,$url,$pagesize)

 if($page==”” || $page>$pagecount)
 {
  $page=1;
 }
 echo(“记录”.$totalrecord.”条 每页”.$pagesize.”条 共”.$pagecount.”页
<a href=”.$url.”1> <<</a>  “);
 if($page>1)
 { 
  echo(“<a href=”.$url.($page-1).”> < </a>
“);
 }  
 if($page+9>$pagecount)
 {
  $current = $pagecount; 
 }
 else
 { 
  $current = $page+9; 
 } 
 for($i=$page;$i<=$current;$i++)
 { 
  echo(“<a href=”.$url.”$i class=’sf’>$i</a> “);
 }
 if($pagecount>$page)
 {
  echo(“<a href=”.$url.($page+1).”> > </a>
“);
 } 
  echo(“<a href=”.$url.$pagecount.”> >></a> “);
}
  ?>
 
</table>
</body>
</html>

发表评论

电子邮件地址不会被公开。 必填项已用*标注