Loop 1 result set, table 1
--------------------------------------------------------
| Id | leiName | Nid | NName | Tid | Title |
| 2 | class name 1 | 4 | mobile phone | 99 | ddddd |
| 3 | class name 2 | 5 | Mobile Phone 1 | 98 | dererd |
| 6 | class name 3 | 3 | mobile phone | 97 | dbbvd |
| 3 | class name 6 | 8 | mobile phone 3 | 96 | 31231dd |
In the descending order of Tid, three results are arranged, for example, ignore with the same NName.
Mobile phone
Mobile phone 1
Mobile phone // same ignore
Mobile phone 3
How to write mysql statements ..
Reply to discussion (solution)
Group by NName
Select * from
(Select * from Table 1 order by Tid desc) tt
Group by NNname;
Select * from
(Select * from Table 1 order by Tid desc) tt
Group by NNname;
Is tt table name 1?
Tt is an alias
Tt is an alias
The sorting of the final result set is messy. Not sorted by Tid.
How are your SQL statements written. We recommend that you post
Create table ....;
Insert into table...; statement
And expected results, and a simple algorithm description.
How are your SQL statements written. We recommend that you post
Create table ....;
Insert into table...; statement
And expected results, and a simple algorithm description.
--------------------------------------------------------
| Id | leiName | Nid | NName | Tid | Title |
| 2 | class name 1 | 4 | mobile phone | 99 | ddddd |
| 3 | class name 2 | 5 | Mobile Phone 1 | 98 | dererd |
| 6 | class name 3 | 3 | mobile phone | 97 | dbbvd |
| 3 | class name 6 | 8 | mobile phone 3 | 96 | 31231dd |
The SQL view is like this. Then sort by Tid,
99 mobile ddddd
98 Mobile Phone 1 dererd
97 it was found that the mobile phone had appeared and ignored it. The main reason was how to ignore it.
96 Mobile Phone 2 31231dd
Forget it. I think the array is used for filtering.
For example
Array
(
[Id] => 39
[XClass] => Super King
[Title] => send
[NURL] =>
[CreateDate] => 15:28:46
)
1
Array
(
[Id] => 32
[DCName] => Xuan
[CURL] =>
[Item1] => Wind
[Nid] = & gt; 62325
[XClass] => Chongtian
[Title] => fsfsd
[CreateDate] => 15:27:28
)
1
Array
(
[Id] => 32
[DCName] => Xuan
[CURL] =>
[Item1] => Wind
[Nid] = & gt; 62324
[XClass] => Chongtian
[Title] => dddddddd43432
[CreateDate] => 15:26:54
)
Obtain the array.
Xclass = Chongtian. Leave one. Use that function.
Why can't I run the #2 SQL code?
To paste the array, paste the data after var_export.
$ Arr = your array; $ t = array (); foreach ($ arr as $ v) {if (! Isset ($ t [$ v ['xclass']) {$ t [$ v ['xclass'] = $ v ;}} print_r (array_values ($ t ));
Why can't I run the #2 SQL code?
To paste the array, paste the data after var_export.
The results are not sorted by Tid. At the same time, when one mobile phone is displayed, the third row is not ignored.
While ($ rsrow = $ result-> fetch_assoc ()){
Echo'
';
print_r($rsrow);
echo '
';
}
The obtained array is as follows:
Array
(
[Id] => 3
[DCName] => Xuan
[CURL] => 3
[Item1] => Tang
[Nid] = & gt; 62326
[XClass] => Super King
[Title] => send
[NURL] =>
[CreateDate] => 15:28:46
)
Array
(
[Id] => 3
[DCName] => Xuan
[CURL] => 3
[Item1] => Tang
[Nid] = & gt; 62325
[XClass] => Chongtian
[Title] => fsfsd
[NURL] =>
[CreateDate] => 15:27:28
)
Array
(
[Id] => 3
[DCName] => Xuan
[CURL] => 3
[Item1] => Tang Shao
[Nid] = & gt; 62324
[XClass] => Chongtian
[Title] => dddddddd43432
[NURL] =>
[CreateDate] => 15:26:54
)
The final filter is ignored when the value of the key xClass appears once every day.
When this function?
Select * from Table 1 group by NNname order by Tid desc
While ($ rsrow = $ result-> fetch_assoc ()){
$ Arr [] = $ rsrow;
}
Then use #10 code
Child paper, you need to check the information for such a problem, so that the results written by others will not help you ~~~~