我尝试在表条件下获取数据然后我想选择如果在成员条件表中有condition_id我想打印出success_img否则打印失败我已经尝试
条件
any([1, 2, 3])
all([1, 2, 3])
会员条件
|---------------------|------------------|------------------|------------------|
| id . | name | success_img | unsuccess_img
|---------------------|------------------|------------------|------------------|
| 1 | name1 . | success | unsuccess
|---------------------|------------------|------------------|------------------|
这是我的HTML
|---------------------|------------------|------------------|------------------|
| id . | condition_id | member_id | add_by
|---------------------|------------------|------------------|------------------|
| 1 | 1 . . | 1 . | admin
|---------------------|------------------|------------------|------------------|
这是我的控制器
<?php foreach ($data['getCoin'] as $item) { ?>
<div class="skill-need-inner">
<div class="skill-need-img">
<?php
if ( !empty($data['condition_id'])) {
if (in_array($item['condition_id'],$data['condition_id'])) {
?>
<img class="" src="<?php echo assets('uploads/'.$item['success']); ?>" alt="scucess" data-toggle="tooltip" data-placement="top" data-original-title="<?php echo $data['add_by']; ?>">
<?php
} else {
?>
<img class="" src="<?php echo assets('uploads/'.$item['unsuccess']); ?>" alt="unsuccess" data-toggle="tooltip" data-placement="top" >
<?php
}
}
?>
</div>
</div>
我的模特测试
$data['getCoin'] = test::getInstance()->getCoin();
$data['getCoinSuccess'] = test::getInstance()->getCoinSuccess(Session::get('member_id'));
if ($data['getCoinSuccess']) {
foreach ($data['getCoinSuccess'] as $itemSuccess) {
$data['condition_id'][] = $itemSuccess['condition_id'];
$data['add_by'][] = $itemSuccess['add_by'];
}
}
在我的尝试中只打印出img成功,但我怎样才能打印出add_by?现在我正在考虑加入表。我知道我的逻辑不好。初学者对此感到抱歉
答案 0 :(得分:0)
我认为以下查询对您有用
SELECT * FROM member_condition
INNER JOIN condition
ON member_condition.condition_id = condition.id
ORDER BY member_condition.condition_id DESC