我有一個查詢獲取一些數據,我需要在我的網頁上顯示。這裏是我的查詢:在不使用循環的情況下顯示查詢中的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行)。不是像我目前正在獲取的八個不同時間。
我該如何解決這個問題?
如果數值始終相同,只需將其顯示在循環外。 –