标题:PHP 从数据库中读取数据分布为一行两列(急!!!)
只看楼主
czg123698741
Rank: 2
等 级:论坛游民
帖 子:348
专家分:84
注 册:2009-3-4
结帖率:78.99%
已结贴  问题点数:0 回复次数:2 
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%">&nbsp;&nbsp;页次:<?php echo $page;?>/<?php echo $page_count;?>页&nbsp;记录:<?php echo $message_count;?> 条&nbsp;</td>
      <td width="63%" align="right">
      <?php
      //如果当前不是首页
      if($page!=1)
      {
          /*  显示“首页”超链接  */
        echo  "<a href=PhotoShow.php?page=1>首页</a>&nbsp;";
        /*  显示“上一页”超链接  */
        echo "<a href=PhotoShow.php?page=".($page-1).">上一页</a>&nbsp;";
      }
      if($page<$page_count)
      {
          /*  显示“下一页”超链接  */
        echo "<a href=PhotoShow.php?page=".($page+1).">下一页</a>&nbsp;";
        /*  显示“尾页”超链接  */
        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 编辑 ]
搜索更多相关主题的帖子: PHP 数据库 
2010-03-03 22:09
好学
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
帖 子:622
专家分:318
注 册:2004-5-4
得分:0 
程序代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. xmlns="http://www. 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);
    echo '<tr bgcolor="#ffffff">';
    $n = 0;
    do
    {
        ?>
        <td><?php echo '<a href="'.$row->PhotoSrc.'">'.'<img src="'.'./images/'.$row->PhotoNmae.'" />'.'</a>'; ?></td>
        <?php
        if($n>0 && $n%2==0){
            echo '</tr><tr bgcolor="#ffffff">';
        }
        $n++;
    }
    echo '</tr>';
    while($row=mysql_fetch_object($sql));
}
?>
</table>
<br>
<table width="550" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td width="37%">&nbsp;&nbsp;页次:<?php echo $page;?>/<?php echo $page_count;?>页&nbsp;记录:<?php echo $message_count;?> 条&nbsp;</td>
      <td width="63%" align="right">
      <?php
      //如果当前不是首页
      if($page!=1)
      {
          /*  显示“首页”超链接  */
        echo  "<a href=PhotoShow.php?page=1>首页</a>&nbsp;";
        /*  显示“上一页”超链接  */
        echo "<a href=PhotoShow.php?page=".($page-1).">上一页</a>&nbsp;";
      }
      if($page<$page_count)
      {
          /*  显示“下一页”超链接  */
        echo "<a href=PhotoShow.php?page=".($page+1).">下一页</a>&nbsp;";
        /*  显示“尾页”超链接  */
        echo  "<a href=PhotoShow.php?page=".$page_count.">尾页</a>";
      }
      mysql_free_result($sql);
      mysql_close($conn);
      ?>
      </td>
    </tr>
</table>
</body>
</html>
2010-03-03 22:42
czg123698741
Rank: 2
等 级:论坛游民
帖 子:348
专家分:84
注 册:2009-3-4
得分:0 
thank
2010-03-04 21:24



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-298518-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.018715 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved