php - Select from 2 MySQL tables in same statement -
i need select data 1 mysql table , match id query email address second table. output results. current code is:
$sql = "select fk_i_user_id, i_amount osei_t_payment_pro_wallet i_amount > 0 order i_amount desc"; $rows = mysqli_query($conn, $sql); while ($rs = mysqli_fetch_array($rows, mysqli_assoc)){ $uid = $rs["fk_i_user_id"]; $cash = $rs["i_amount"] / 1000000; echo "user id - ".$uid." wallet val - ".$cash.chr(10).chr(13); }
i incorporate in query:
"select s_email osei_t_user pk_i_id =".$uid;
and output results:
echo "user id - ".$uid." wallet val - ".$cash." - email: ".(value above query).chr(10).chr(13);
you can use join. use outer join if second table's record may not present:
select fk_i_user_id,i_amount, s_email osei_t_payment_pro_wallet left outer join osei_t_user on pk_i_id=fk_i_user_id i_amount > 0 order i_amount desc
the outer join selects records match on clause, fields null if there no matching record parent table (osei_t_payment_pro_wallet).
updated output (from op):
$email = $rs["s_email"]; echo "user id - ".$uid." wallet val - ".$cash." email -".$email.chr(10).chr(13);
though write this:
echo "user id - {$uid} wallet val - {$cash} email - {$email}\n\r";
you use results directly:
echo "user id - {$rs["fk_i_user_id"]} wallet val - {$cash} email - {$rs["s_email"]}\n\r";
$cash
still needs calculated.
wiki
Comments
Post a Comment