如何使用数组中的值获取查询的结果?
问题描述:
这是我的函数,其中i取我的结果从数据库如何使用数组中的值获取查询的结果?
function Prof_Viewer($MemberId)
{
$query = $this->db->query("SELECT distinct(t1.dProfileId) as prof
FROM tbl_profile_viewer as t1
JOIN tbl_login as t2
WHERE t1.dProfileViwerId='$MemberId'");
if($query->num_rows > 0)
{
foreach($query->result() as $row)
{
echo $row->prof;//i am receiving many values here
$query1 = $this->db->query("SELECT distinct(t3.dUser_name),t2.dPath,t3.dCreatedDate
FROM tbl_login as t3
JOIN tbl_profile_viewer as t1,
tbl_member_details as t2
WHERE t3.dMember_Id = '$row->prof'
AND t2.dMember_Id ='$row->prof'");
}
return $query1->result_array();
}
}
正如上面评论我接收许多值,而回声变量$行向>教授; 说我有值,如1 2和3 ....... 即使我有这三个值我'query1'
只取最后一个值。因此,我只有一个结果我希望查询被执行1和2也 如何实现这一点
答
您可以使用PHP的explode()将您的字符串转换为数组。例如:
<?php
$str = 'one|two|three|four';
// positive limit
print_r(explode('|', $str));
// gives you an array:
Array
(
[0] => one
[1] => two
[2] => three
[3] => four
)
?>
但我认为你会更好,如果你学会了如何做JOIN的:
答
我假设你在这里使用的mysqli。
Result_fetch_array()会做你想做的事
http://au2.php.net/manual/en/mysqli-result.fetch-array.php