PHP queries mysql. according to the ID card field, sort by date of birth. my mysql data table "person" contains an ID card number field, that is, sort by the seventh to 14th fields in the ID card number. The focus is sorting. The statement for creating the person table is as follows:
$ Persql = "create table person
(
ID int not null AUTO_INCREMENT,
PersonID char (18) not null,
PersonName varchar (20 ),
HomeID int,
About varchar (10 ),
Sex varchar (4 ),
Edu varchar (8 ),
Mz varchar (4 ),
Primary key (ID ),
UNIQUE (personID)
) ENGINE = InnoDB default charset = utf8 ";
Query statement $ SQL = "SELECT * FROM person ";
$ Sp = mysql_query ($ SQL, $ con );
The personID field stores the ID number. I want to output all fields, as shown in,
It is expected to be sorted by the date of birth.
Currently, I am thinking of storing data in a two-dimensional array.
$ Arr = array ();
$ I = 0;
While ($ row = mysql_fetch_array ($ sp )){
$ Arr [$ I] = $ row;
$ I ++;
}
Sort two-dimensional arrays and then output them. However, I think this method is too troublesome and I hope there will be better methods.
Reply to discussion (solution)
The sorting can be performed in mysql.
SELECT * FROM person order by SUBSTRING (personID, 7,8) desc
SELECT * FROM person order by SUBSTRING (personID, 6, 13) desc
Thank you! This function is too easy to use and get a new skill.