0

以下是我的代码,我试图在其中显示来自同一个表的值,但在我的 HTML 表的不同列中显示不同的 id,比如假设我的表有三列,然后在每一列中显示不同的值

我只希望我各自的 id 在同一张表中显示的数据的每一列上发生变化

类似于: ID1 的值 | ID2 的值 | ID3 的值

但目前我正在做这样的事情:ID1的值| ID1 的值 | ID1 的值

请让我知道如何修复以下代码:

          <table width="714" height="318" border="0" align="right" cellpadding="2" cellspacing="0">
          <?php $count=0; do { 
                  { ++$count;

          ?> <tr>
            <td width="231" height="288" valign="top" background="images/viv.png"><div align="center"><img src="get.php?id=<?php echo $row_Recordset1['ID']; ?>"  width="270" height="270" /><br />
                <br />
              <a href="get_deal.php?id=<?php echo $row_Recordset1['ID']; ?>"><img src="button.png" width="182" height="36" border="0" /></a><br />
              <br />
            </div></td>
            <td width="231" valign="top" background="images/viv.png"><div align="center"><img src="get.php?id=<?php echo $row_Recordset1['ID']; ?>"  width="270" height="270" /><br />
                    <br />
                    <a href="get_deal.php?id=<?php echo $row_Recordset1['ID']; ?>"><img src="button.png" width="182" height="36" border="0" /></a><br />
                    <br />
            </div></td>
            <td width="231" valign="top" background="images/viv.png"><div align="center"><img src="get.php?id=<?php echo $row_Recordset1['ID']; ?>"  width="270" height="270" /><br />
                    <br />
                    <a href="get_deal.php?id=<?php echo $row_Recordset1['ID']; ?>"><img src="button.png" width="182" height="36" border="0" /></a><br />
                    <br />
            </div></td>
          </tr>
              <tr>
                <td height="23" valign="top">&nbsp;</td>
                <td valign="top">&nbsp;</td>
                <td valign="top">&nbsp;</td>
              </tr>
              <?php }

              } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
if ($count == 0)
            echo '<span style="font-family:Tahoma;color:white;font-size:200%">No Deals Available</span>';   ?>
        </table></td>
      </tr>
    </table>

解决方案: http ://www.qualitycodes.com/tutorial.php?articleid=33&title=Displaying-Records-in-Multiple-Columns-Using-PHP

4

1 回答 1

3

您一直在回$row_Recordset1['ID'];显,这意味着您一直在显示 ID 列。您必须更改ID为要显示的列的名称。

在这种情况下,他们继续做 ID1 所以如果所有三个值都是 ID 那么你需要在你的选择中做别名(称它们不同的名字),这样你就可以使用ID1,ID2ID3

例如,如果您当前的 sql 查询是:

select *
from tablex.....

然后你现在必须提取列并命名它们:

select tablex.ID as ID1, secondTable.ID as ID2, thirdTable.ID as ID3
from tablex.....

然后您可以将它们称为ID1,ID2ID3

于 2012-06-14T20:30:12.610 回答