PHP嵌套do-while循环

时间:2017-10-02 23:33:48

标签: php

我试图教自己php ....我创建了一个包含4个元素的数据库... region,details,store_name,web_address。

我创建了ado-while循环,显示'region'中的所有记录...它显示'store_name',然后'web_address',然后'详细信息'排序,所以具有相同'详细信息'的所有记录都是聚集在一起;

<table width="600" align="center" border="0" cellspacing="4" >
  <tr>
    <td colspan="2"><h2>Web Stockists: <strong></strong></h2></td>
    <td width="251" colspan="2" align="right"><h3>Region: <?php echo $region_text ?></h3></td>
  </tr>
  <?php do { ?>

    <tr>
      <td colspan="2"><strong><?php echo $row_RegionList['store_name']; ?></strong></td>
      <td colspan="2" rowspan="2" align="center">    <?php echo '<a href="http://' . $row_RegionList['web_address'] . '" target="_blank">' . $row_RegionList['web_address'] . '</a>'; ?></td>
    </tr>
    <tr>
      <td width="14">
      <td width="313"><?php echo $row_RegionList['details']; ?>          </tr>
    <?php } while ($row_RegionList = mysql_fetch_assoc($RegionList)); ?>
</table>

我现在想要这样做,以便每个具有相同“详细信息”值的记录都列在“详细信息”子标题下。

这是我的尝试;

<table width="600" align="center" border="0" cellspacing="4" >
  <tr>
    <td colspan="2"><h2>Web Stockists: <strong></strong></h2></td>
    <td width="251" colspan="2" align="right"><h3>Region: <?php echo $region_text ?></h3></td>
  </tr>
  <?php     $details = $row_RegionList['details'];
        do {  ?>
  <tr>
  <td width="313"> <h3><?php echo $row_RegionList['details']; ?> </h3></td>
  </tr>
  <?php do { ?>
    <tr>
      <td colspan="2"><strong><?php echo $row_RegionList['store_name']; ?></strong></td>
      <td colspan="2" rowspan="2" align="center">    <?php echo '<a href="http://' . $row_RegionList['web_address'] . '" target="_blank">' . $row_RegionList['web_address'] . '</a>'; ?></td>
    </tr>
  <?php } while ($row_RegionList['details'] == $details); 

    $details = $row_RegionList['details'];

     } while ($row_RegionList = mysql_fetch_assoc($RegionList)); ?>
</table>

这使得'region'标题的子标题为'details',但随后会在数据库中创建第一条记录的永久循环。谁能告诉我我做错了什么?

0 个答案:

没有答案
相关问题