我想同时从不同字段的2个不同表中获取两个不同的值

时间:2015-10-23 05:17:22

标签: php sql

我有2个表名为p_orderp_customer

我必须从相应的字段中获取P_order_noP_customer_name的值

<?php
      $wherecat = "`p_order_status` = 'active'";
      $catsql =$general->GetRows('*' ,'p_order' ,$wherecat);
      $catRes = mysql_num_rows($catsql);
       <p><muted></muted><br/>
          <a href="#">customer name =</a>order no =<br/>
       </p>
 ?>

3 个答案:

答案 0 :(得分:0)

试试这个MySQL查询: -

select P_order_no, P_customer_name from p_customer 
inner join p_order on 
(P_customer_id = P_order_customer_id && p_order_status = 'active')

答案 1 :(得分:0)

尝试此Illuminate\Database\Eloquent\Collection查询: -

demo

答案 2 :(得分:0)

要从两个表中检索值,您必须对其使用操作。对于实现连接,至少需要一个公共列。

select p_order.P_order_no, p_customer.P_customer_name from p_customer join p_order on  p_customer.customer_id = p_order.customer_id