2010-06-29 135 views
0

這是我的函數,其中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也 如何實現這一點

回答

1

您可以使用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的:

http://en.wikipedia.org/wiki/Join_(SQL)

相關問題