こんにちは、何がうまくいかないのか理解するのに苦労しています..
このステートメントをmysqlで実行すると..
select brand_id, brand_name,
max(case when group_row_number = 1 then linecode end) Code1,
max(case when group_row_number = 2 then linecode end) Code2,
max(case when group_row_number = 3 then linecode end) Code3,
max(case when group_row_number = 4 then linecode end) Code4,
max(case when group_row_number = 5 then linecode end) Code5,
max(case when group_row_number = 6 then linecode end) Code6,
max(case when group_row_number = 7 then linecode end) Code7,
max(case when group_row_number = 8 then linecode end) Code8,
max(case when group_row_number = 9 then linecode end) Code9,
max(case when group_row_number = 10 then linecode end) Code10
from ( select brand_id, brand_name, linecode,
@num := if(@brand_id = `brand_id` AND @brand_name = `brand_name`, @num + 1, 1) as
group_row_number, @brand_id := `brand_id` as dummy,
@brand_name := `brand_name` as linedummy from linecodes_temp )
src group by brand_id, brand_name order by if(linecode = '' or linecode is null,1,0),
brand_name ASC;
私は私が望む結果を受け取ります。
+----------+----------------------------------------------------+-------+-------+-------+-------+-------+-------+-------+-------+-------+--------+
| brand_id | brand_name | Code1 | Code2 | Code3 | Code4 | Code5 | Code6 | Code7 | Code8 | Code9 | Code10 |
+----------+----------------------------------------------------+-------+-------+-------+-------+-------+-------+-------+-------+-------+--------+
| DPQT | 1-800 Tow Truck | DCF | DCA | AAA | DDD | DER | NULL | NULL | NULL | NULL | NULL |
| BLGR | 1-800-Radiator | Curt | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
| BGVM | 100+ Manufacturing/Coyote | ASC | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
| DPQS | 10C Technologies Inc | ASQ | AQW | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
| FDJG | 2 Cool AirVents | CAS | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
| DWFD | 31 Incorporated | ASD | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
| BBBB | 3M | snoop | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL | NULL |
これは完璧です。
しかし、振り返ってphpで呼び出すと.
$result = mysql_query("select brand_id, brand_name, max(case when group_row_number = 1 then linecode end) Code1, max(case when group_row_number = 2 then linecode end) Code2, max(case when group_row_number = 3 then linecode end) Code3, max(case when group_row_number = 4 then linecode end) Code4, max(case when group_row_number = 5 then linecode end) Code5, max(case when group_row_number = 6 then linecode end) Code6, max(case when group_row_number = 7 then linecode end) Code7, max(case when group_row_number = 8 then linecode end) Code8, max(case when group_row_number = 9 then linecode end) Code9, max(case when group_row_number = 10 then linecode end) Code10 from ( select brand_id, brand_name, linecode, @num := if(@brand_id = `brand_id` AND @brand_name = `brand_name`, @num + 1, 1) as group_row_number, @brand_id := `brand_id` as dummy, @brand_name := `brand_name` as linedummy from linecodes_temp ) src group by brand_id, brand_name order by if(linecode = '' or linecode is null,1,0), brand_name ASC",$dbh);
そして、
while($row = mysql_fetch_assoc($result)) {
そしてテーブルを通り抜けます
私が得る結果は
brand_id brand_name Code1 Code2 Code3 Code4 Code5 to Code 10
DPQT 1-800 Tow Truck DER
BLGR 1-800-Radiator Curt
BGVM 100+ Manufacturing/Coyote ASC
DPQS 10C Technologies Inc ASQ
FDJG 2 Cool AirVents CAS
DWFD 31 Incorporated ASD
BBBB 3M snoop
var_dump($row) を実行すると、上記の php クエリの結果が表示されるので、その点で何も悪いことをしていないことがわかります
私はmysqlとphpの両方でまったく同じクエリを使用しています.mysql_queryを呼び出すときにphpに構文の違いがあると仮定しています.
誰かが助けてくれたら、とても感謝しています
お時間をいただきありがとうございます。