0
我有一個while循環打印出搜索結果中的行,搜索結果中的一列是'Area Name'。 現在我想檢查該區域名稱是否也在另一個結果集中,如果是,請使產品可點擊。PHP檢查一個值是否等於另一個結果集中的任何值?
這是我的搜索結果,而循環:
<table id="" class="table table-striped table-bordered display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Customer Code</th>
<th>Customer Name</th>
<th>Customer Type</th>
<th>Name</th>
<th>Postcode</th>
</tr>
</thead>
<tbody>
<?php while($customer = sqlsrv_fetch_array($querySearchResults, SQLSRV_FETCH_ASSOC)) : ?>
<tr>
<td><?php echo $customer['CardCode'] ?></td>
<td>
//If $customer['Name'] = to any of the rows in other query
//This is Clickable
<?php echo $customer['CardName']; ?>
//Else its not.
</td>
<td><?php echo $customer['CardType'] ?></td>
<td><?php echo $customer['Name'] ?></td>
<td><?php echo $customer['ZipCode'] ?></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
這是其他查詢:
$userID = $user['loggedInUserId'];
$queryName = "
SELECT UserID, Name
FROM Table
WHERE UserID = '$userID'";
$getName = sqlsrv_query($sapconn2, $queryName);
$Name = sqlsrv_fetch_array($getName, SQLSRV_FETCH_ASSOC);
會是什麼樣的if語句需要在這種情況下?
如果結果在數組中,您可以使用'in_array()'進行檢查。 –
這裏的代碼不一致。 '另一個查詢'似乎只返回一行或者你至少你只是檢索一行!所以如果這樣的話,所有你需要做的就是'if($ customer ['Name'] == $ Name ['name']){' – RiggsFolly
是的,我明白你的意思,它只會返回一行,不是嗎?這就是我錯誤的地方,我可能不得不改變我的SQL以包含另一個WHERE子句並檢查。感謝您的意見 – PHPNewbie