PHP 从数据库中读取数据分布为一行两列(急!!!)
代码:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<table width="550" border="1" cellpadding="1" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#999999">
<?php
include("DBhelper.php");
mysql_query("set names gb2312");
if ($page=="")
{
$page=1;
}
if (is_numeric($page))
{
$page_size=4;
$query="select count(*) as total from photos order by id desc";
$result=mysql_query($query); //查询符合条件的记录总条数
$message_count=mysql_result($result,0,"total"); //要显示的总记录数
$page_count=ceil($message_count/$page_size); //根据记录总数除以每页显示的记录数求出所分的页数
$offset=($page-1)*$page_size; //计算下一页从第几条数据开始循环
$sql=mysql_query("SELECT PhotoNmae,PhotoSrc FROM photos order by Id desc limit $offset, $page_size");
$row=mysql_fetch_object($sql);
do
{
?>
<tr bgcolor="#ffffff">
//这个是循环体,我想一行显示两列数据,但是这样的话,这两列的数据都是一样的!!!我不想这样,我想每一个表格元素都显示不同的数据。请大家帮帮忙啊!!!!!!!!!谢谢
<td><?php echo '<a href="'.$row->PhotoSrc.'">'.'<img src="'.'./images/'.$row->PhotoNmae.'" />'.'</a>'; ?></td>
<td><?php echo '<a href="'.$row->PhotoSrc.'">'.'<img src="'.'./images/'.$row->PhotoNmae.'" />'.'</a>'; ?></td>
</tr>
<?php
}
while($row=mysql_fetch_object($sql));
}
?>
</table>
<br>
<table width="550" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="37%"> 页次:<?php echo $page;?>/<?php echo $page_count;?>页 记录:<?php echo $message_count;?> 条 </td>
<td width="63%" align="right">
<?php
//如果当前不是首页
if($page!=1)
{
/* 显示“首页”超链接 */
echo "<a href=PhotoShow.php?page=1>首页</a> ";
/* 显示“上一页”超链接 */
echo "<a href=PhotoShow.php?page=".($page-1).">上一页</a> ";
}
if($page<$page_count)
{
/* 显示“下一页”超链接 */
echo "<a href=PhotoShow.php?page=".($page+1).">下一页</a> ";
/* 显示“尾页”超链接 */
echo "<a href=PhotoShow.php?page=".$page_count.">尾页</a>";
}
mysql_free_result($sql);
mysql_close($conn);
?>
</td>
</tr>
</table>
</body>
</html>
[ 本帖最后由 czg123698741 于 2010-3-3 22:39 编辑 ]