PHP two-dimensional array counting and output problem data are as follows
Array
(
[Pn] => 007-023
[Pn_from] => Stock
)
Array
(
[Pn] => 007-007
[Pn_from] => Stock
)
Array
(
[Pn] => 007-023
[Pn_from] => BU Warranty
)
The purpose is to calculate the number of repetitions in the pn and merge a new two-dimensional array.
Array
(
[Pn] => 007-023
[Pn_qty] => 2
[Pn_from] => Stock
)
Array
(
[Pn] => 007-007
[Pn_qty] => 1
[Pn_from] => Stock
)
To calculate the number of duplicates through a loop, it is a bit stuck here ,...
$ SQL _m = "SELECT pn, pn_from FROM pn_s WHERE job_no = 32 ";
$ Result_m = pg_query ($ SQL _m );
$ I = 0;
While ($ row_m = pg_fetch_array ($ result_m )){
Print_r ($ row_m );
$ I ++;
}
Echo"
";
Echo $ I;
Reply to discussion (solution)
SELECT pn, count (*) as pn_qty, pn_from FROM pn_s group by pn
Use group by pn
ERROR: column "pn_s.pn_from" must appear in the group by clause or be used in an aggregate function
Not sure .. Pn_from must be reflected in the group by statement or judgment statement, but I have other fields to determine the required rows ..
This is data ..
First obtain an array (pn1, pn2, pn3 ,...)
Then use the array_count_values () function
Then, process the result into the final array you want...
The data is incorrect .. Submit it again .. Thank you very much for your help.
The data is as follows:
Array
(
[Pn] => 007-023
[Pn_from] => Stock
)
Array
(
[Pn] => 007-007
[Pn_from] => Stock
)
Array
(
[Pn] => 007-023
[Pn_from] => BU Warranty
)
The purpose is to calculate the number of repetitions in the pn and merge a new two-dimensional array.
Array
(
[Pn] => 007-023
[Pn_qty] => 2
[Pn_from] => Stock
)
Array
(
[Pn] => 007-007
[Pn_qty] => 1
[Pn_from] => Stock
)
To calculate the number of duplicates through a loop, it is a bit stuck here ,...
$ SQL _m = "SELECT pn, pn_from FROM pn_s WHERE job_no = 32 ";
$ Result_m = pg_query ($ SQL _m );
$ I = 0;
While ($ row_m = pg_fetch_array ($ result_m )){
Print_r ($ row_m );
$ I ++;
}
Echo"
";
Echo $ I;
The data is incorrect .. Submit it again .. Thank you very much for your help.
This is data ..
The same was originally true, but the cycle was too bloated ..
Select pn, pn_from, count (pn) from pn_s where job_no = 32 group by pn, pn_from thank you! Some friends in the PG Group helped write an SQL...