douzi4724 2010-06-29 04:46
浏览 19
已采纳

如何使用数组中的值获取查询结果?

This is my function where i fetch my results from database

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();
  }
}

As commented above i receive many values while echo the variable $row->prof; say i have values such as 1 2 and 3....... Even if i have these three values my 'query1' takes only the last value .so i have only one result i want the query to be executed for 1 and 2 also how to Achieve that

  • 写回答

2条回答 默认 最新

  • duandongjin5647 2010-06-29 04:57
    关注

    You can just use PHP's explode() to convert your string into an array. For example:

    <?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
    )
    
    ?>
    

    But I think you would be better off if you learned how to do JOIN's:

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路