我有一个查询获取一些数据,我需要在我的网页上显示。这里是我的查询:在不使用循环的情况下显示查询中的PHP数据
$sql1 = "SELECT CAST([Series] AS INT) AS Series
,[Master Supplier Title]
,[Fund Name]
,CAST([Agreement_ID] AS INT) AS Agreement_ID
,CAST([Tier_ID] AS INT) AS Tier_ID
,[Retro_to_1]
,CAST([Payments per Year] AS INT) AS [Payments per Year]
,[Condition Unit of Measure]
,CAST([Condition Minimum] AS INT) AS [Condition Minimum]
,CAST([Condition Maximum] AS INT) AS [Condition Maximum]
,CAST([Incentive Multiplier] AS DEC(5,4)) AS [Incentive Multiplier]
FROM [Test].[dbo].[vExample]
WHERE [Master Supplier Title] = '$supp' AND [Series] = 1 AND [Fund Name] = '400P' AND [Agreement_ID] = 2
ORDER BY [Master Supplier Title]";
然后我使用这个代码块来显示所需要的结果:
<?php foreach ($pdo->query($sql1) as $supp11) { ?>
<label>Agreement ID:</label><input value="<?php echo $supp11['Agreement_ID'];?>" readonly><br><br><br>
<table>
<tr>
<thead>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
<th></th>
</thead>
</tr>
<?php foreach ($pdo->query($sql1) as $supp22) { ?>
<tr>
<tbody>
<td><?php echo $supp22['Tier_ID'];?></td>
<td><?php echo $supp22['Incentive Multiplier'];?></td>
<td><?php echo $supp22['Condition Minimum'];?></td>
<td><?php echo $supp22['Condition Maximum'];?></td>
<td><?php echo $supp22['Condition Unit of Measure'];?></td>
<td><?php echo $supp22['Retro_to_1'];?></td>
<td><?php echo $supp22['Payments per Year'];?></td>
</tbody>
</tr>
<?php } ?>
</table>
<?php } ?>
您看到的变量$supp
的是,我从下拉列表中选择获得值我有一些以前的代码。
每当我做出下拉选择时,它会显示正确的数据。但是,我只需要它在一张表中显示一次。例如,选择可能在数据库的多行中。因此,只要它在表格中显示结果,它就会在表格中显示数据库中下拉选择的次数。所以,如果我的$supp
变量中的值在数据库中看到了8次,那么我只需要一次一个表中的该信息(8行)。不是像我目前正在获取的八个不同时间。
我该如何解决这个问题?
如果数值始终相同,只需将其显示在循环外。 –