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 goal is to calculate the number of repetitions in the PN, merging 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
)
Want to calculate the repetition by the loop, do a bit of jam 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
Using GROUP by PN
Error:column "Pn_s.pn_from" must appear in the GROUP by clause or being used in an aggregate function
I can't make a mistake. Pn_from must be reflected in the group by or judgment statement, but I have another field to judge the desired line.
Here's the data.
Get an array first (PN1,PN2,PN3,...) The array
Then use the Array_count_values () function
Then the result is processed into your last desired array ...
Incorrect data: Re-submit: Thanks for the help of two-bit
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 goal is to calculate the number of repetitions in the PN, merging 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
)
Want to calculate the repetition by the loop, do a bit of jam 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;
Incorrect data: Re-submit: Thanks for the help of two-bit
Here's the data.
It was the same thought, 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! The PG Group has a friend to help write a SQL ...