-1

我想将数据库中的数据拆分为表的三列,但我不知道该怎么做我已经尝试过,但它不能正常工作请帮助我提前谢谢

 <?php
 $count=1;
$query1=mysql_query(" SELECT *,category.id ids FROM category INNER JOIN products ON  category.`cid`=products.`cid` WHERE category.id='$id' ") or die ('Product Query Problem');
    while($row1=mysql_fetch_array($query1))
    {
    $count++;
?>

我想将数据库中的数据拆分为表的三列,但我不知道该怎么做我已经尝试过,但它不能正常工作请帮助我提前谢谢

 <div class="main_content">

<div class="featured-items clearfix">
<div class="items clearfix">
<table border="0">
<tr>
<td><div class="item-block-1">
<div class="image-wrapper">
<div class="image">
<div class="overlay">
<div class="position">
<div>
<p><?php echo $row1['description']; ?></p>
<a href="pandora-homepage.html#" class="quickshop">Quick shop</a>
</div>
</div>
</div>
<a href=""><img src="products/images/photos/photo-2.jpg" style="margin: -27.5px 0 0 0;" alt="" /></a>
</div>
</div>
<h2><a href=""><?php echo $row1['product']; ?></a></h2>
<p class="price"><?php echo $row1['price']; ?></p>
</div>
<?php
if($count%3==1)
{

    ?></td></tr>
  </table>
<?php   }}?>
</div>
</div>
</div>
4

2 回答 2

1

您将在此处找到从 php 创建 html 表的非常清晰的示例。我复制了一些相关的行:

if(mysql_num_rows($result2)) {
    echo '<table cellpadding="0" cellspacing="0" class="db-table">';
    echo '<tr><th>Field</th><th>Type</th><th>Null</th><th>Key</th><th>Default<th>Extra</th></tr>';
    while($row2 = mysql_fetch_row($result2)) {
       echo '<tr>';
       foreach($row2 as $key=>$value) {
           echo '<td>',$value,'</td>';
       }
       echo '</tr>';
    }
    echo '</table><br />';
}

它与表中的所有列相呼应——如果你想做一些不同的事情,你可以改变内部foreach循环。我希望这有帮助!

于 2013-02-07T15:44:43.920 回答
0

尝试这个

      <?php
  $count=1;
 ?>
 <div class="main_content">

<div class="featured-items clearfix">
<div class="items clearfix">
<table border="0">

<?
$query1=mysql_query(" SELECT *,category.id ids FROM category INNER JOIN products ON   category.`cid`=products.`cid` WHERE category.id='$id' ") or die ('Product Query Problem');
 while($row1=mysql_fetch_array($query1))
 {
 $count++;
 ?>

  <tr><td><div class="item-block-1">
  <div class="image-wrapper">
  <div class="image">
  <div class="overlay">
  <div class="position">
  <div>
   <p><?php echo $row1['description']; ?></p>
   <a href="pandora-homepage.html#" class="quickshop">Quick shop</a>
  </div>
  </div>
  </div>
 <a href=""><img src="products/images/photos/photo-2.jpg" style="margin: -27.5px 0 0 0;" alt="" /></a>
  </div>
  </div>
  <h2><a href=""><?php echo $row1['product']; ?></a></h2>
  <p class="price"><?php echo $row1['price']; ?></p>
  </div>
  <?php
   if($count%3==1)
    {

    ?></td></tr>
   <?php   }}?>
  </table>
  </div>
  </div>
  </div>
于 2013-02-07T15:36:17.840 回答