【发布时间】:2025-09-20 05:50:01
【问题描述】:
我有这个代码
<?php
$query1 = "SELECT users.id,
testtable_result.id as result_id,
testtable_result.user_id,
testtable_result.cad_id,
testtable_result.medication,
testtable_result.color,
testtable_category.category_id,
testtable_category.name
FROM users
INNER JOIN testtable_result
ON testtable_result.user_id=users.id
INNER JOIN testtable_category
ON testtable_result.cad_id=testtable_category.category_id
WHERE users.id = '{$userID}' AND color LIKE '%blue%';";
$result1 = query($query1);
confirm($result1);
if (row_count($result1) > 0) :
while($row1 = fetch_Array($result1)) {
$medication = $row1['medication'];
$data[] = $row1;
}
foreach ($data as $value) {
$categoryname = $value['name'];
$medication = $value['medication'];
$arrmaincatname = explode('(', rtrim($categoryname, ')'));
if($categoryname == "Saba"){
$datacat = $arrmaincatname[0];
$medicacat = $medication; ?>
In <?php echo $datacat; ?> category -- [<?php echo $medicacat ?>]
<?php
}} ?>
它显示这样的结果
在 Saba 类别中 -- [ProAir RespiClick®] 在 Saba 类别中 -- [Proventil® HFA]
我想删除所有重复的结果,并希望这样显示。
在 Saba 类别中 -- [ProAir RespiClick®、Proventil® HFA]
【问题讨论】:
-
你能添加你正在使用的数组的结构吗?
-
请添加一些$data的例子
-
@Sena,我已经更新了问题