Mysql_fetch_array( $result, MYSQL_BOTH ) 不准确 [英] Mysql_fetch_array( $result, MYSQL_BOTH ) is not exact

查看:46
本文介绍了Mysql_fetch_array( $result, MYSQL_BOTH ) 不准确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

mysql_fetch_array( $result , MYSQL_BOTH ) 有一个奇怪的问题.这是问题的重现方式:

I have a weird problem with mysql_fetch_array( $result , MYSQL_BOTH ). This is how the problem is reproduced:

  1. 做一个使用LEFT JOINGROUP BY
  2. 的查询字符串
  1. Do a query string that uses LEFT JOIN, GROUP BY

    select *, 
           (A1.total - A2.borrow_total) as remain_total 
      from ( select Min(sample_created_date) as created_date, 
             sample_model,
             sample_ncc, 
             count(*) as total , 
             sample_sort 
              from tb_sample 
             where 1=1 
               AND sample_kho IN ( 'hanoi','tm_hanoi' ) 
             group by sample_model, sample_sort, sample_ncc 
           ) A1 left join 
           ( select sample_model as sample_model1, 
                    count(*) as borrow_total, 
                    sample_ncc 
               from tb_sample B1 left join tb_sample_ticket B2 
                 on B1.sample_borrow_status = B2.ticket_id 
              where 1=1 
                and ticket_bo_phan_duyet = 'finish' 
                and ticket_status_duyet = '1' 
                AND sample_kho IN ( 'hanoi','tm_hanoi' ) 
              group by sample_model, sample_ncc 
            ) A2 on A1.sample_model = A2.sample_model1 
                AND A1.sample_ncc = A2.sample_ncc left join tb_product_sort A3 
                 on A1.sample_sort = A3.sort_code 
    where 1=1 
    order by created_date DESC 
    LIMIT 0, 30

  1. 实现mysql_fetch_array( $result , MYSQL_BOTH ):

$rw  = mysql_fetch_array( $result , MYSQL_BOTH );

  • $rw 的显示值:

    echo  $rw['sample_cc'];
    

  • 但是什么都没有.然后我尝试 print_r( $rw ),结果如下:

    But there is nothing. Then I try print_r( $rw ), see below for the result:

    Array
    (
        [0] => 2013-06-13 04:10:39
        [created_date] => 2013-06-13 04:10:39
        [1] => 3G
        [sample_model] => 3G
        **[2] => Gmobile
        [sample_ncc] =>** 
        [3] => 1
        [total] => 1
        [4] => SIM
        [sample_sort] => SIM      
    );
    

    我看到 $Rw[2] = 3G$rw['sample_ncc'] 为空>.

    I see that $Rw[2] = 3G but $rw['sample_ncc'] is null.

    这是一个奇怪的问题.请帮我解决.

    This is a weird problem. Please help me solve it.

    推荐答案

    尝试为 A1A2 子查询中的 sample_ncc 列提供显式别名>(例如 sample_ncc_a1sample_ncc_a2)或仅返回位于 LEFT JOIN 左侧的一个(表示 A1代码>).

    Try to give explicit aliases for sample_ncc columns in subqueries A1 and A2 (e.g. sample_ncc_a1 and sample_ncc_a2) or return only one that is on the left side of LEFT JOIN (meaning in A1).

    这篇关于Mysql_fetch_array( $result, MYSQL_BOTH ) 不准确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆