学习php,我现在正试图解决这个问题。请帮忙。
如何通过此USER_ID转到另一个表(USER)并获取名称(REALNAME),这两个表中的相同?
if ( $_POST ) {
$team_id = abs(intval($_POST['team_id']));
$consume = $_POST['consume'];
if (!$team_id || !$consume) die('-ERR ERR_NO_DATA');
$condition = array(
'team_id' => $team_id,
'consume' => $consume,
);
$coupons = DB::LimitQuery('coupon', array(
'condition' => $condition,
));
if (!$coupons) die('-ERR ERR_NO_DATA');
$team = Table::Fetch('team', $team_id);
$name = 'coupon_'.date('Ymd');
$kn = array(
'id' => 'ID',
'secret' => 'Password',
'date' => 'Valid',
'consume' => 'Status',
);
$consume = array(
'Y' => 'Used',
'N' => 'Unused',
);
$ecoupons = array();
foreach( $coupons AS $one ) {
$one['id'] = "#{$one['id']}";
$one['consume'] = $consume[$one['consume']];
$one['date'] = date('Y-m-d', $one['expire_time']);
$ecoupons[] = $one;
}
down_xls($ecoupons, $kn, $name);
答案 0 :(得分:0)
您需要JOIN SQL查询中的表
SELECT something FROM coupons as coupons JOIN user as user ON coupons.id=user.id
答案 1 :(得分:0)
如果要从两个表中检索详细信息,则应使用join。 根据user_id加入表COUPON和表USER。这应该产生你想要的结果。