PHP controls MySQL multi-condition query and makes a PHP database query page. now you can enter the version number and select the line for query. the selection status is unavailable. the page is as follows,
Currently, the problem is that when you open the page for the first time, all data is automatically displayed and two errors are Prompted. how to modify the error? that is, the page is blank, the message is displayed only after you click "query". The second question is how to make the "select status" take effect. select "finish execution SQL1" and select "unfinished execution SQL2". The media version number and line are required,
The one who helped change.
The code for selecting status is written in this way, but the code cannot be executed and a syntax error is prompted.
If % {$ _ REQUEST ['zhuangtai']} % = "finished" then
$ Q = "SELECT * FROM research where banben like '% {$ _ REQUEST ['banben']} %' AND linename like '% {$ _ REQUEST ['xianlu']} % 'AND zhuangtai = 'Fin' order by busname asc ";
Elseif % {$ _ REQUEST ['zhuangtai']} % = "unfinished" then
$ Q = "SELECT * FROM research where banben like '% {$ _ REQUEST ['banben']} %' AND linename like '% {$ _ REQUEST ['xianlu']} % 'AND zhuangtai = 'new' order by busname asc ";
Complete code:
Data Query
$ Link = mysql_connect ("localhost", "root", "12345678 ");
If (! $ Link) echo "no connection successful! ";
Else echo "connection successful! ";
Mysql_select_db ("busap", $ link); // select a database
// Control query conditions
// If % {$ _ REQUEST ['zhuangtai']} % = "finished" then
$ Q = "SELECT * FROM research where banben like '% {$ _ REQUEST ['banben']} %' AND linename like '% {$ _ REQUEST ['xianlu']} % 'AND zhuangtai = 'Fin' order by busname asc ";
// Elseif % {$ _ REQUEST ['zhuangtai']} % = "unfinished" then
// $ Q = "SELECT * FROM research where banben like '% {$ _ REQUEST ['banben']} %' AND linename like '% {$ _ REQUEST ['xianlu' ]} % 'AND zhuangtai = 'new' order by busname asc ";
// Mysql_query ("set names GB2312"); // prevents garbled characters
$ Rs = mysql_query ($ q); // Obtain a dataset
$ Assoc = mysql_num_rows ($ rs); // The number of affected rows. mysql_fetch_assoc was used.
Echo "$ assoc ";
$ Row = mysql_fetch_array ($ rs); // you only need to add this row back.
If (! $ Rs) {die ("Valid result! ");}
?>
Line |
Center No. |
Line |
Vehicle ID |
Transmission mode |
Media version |
Date |
Time |
Status |
Do {?>
|
|
|
|
|
|
|
|
|
Reply to discussion (solution)
$ Q = "SELECT * FROM research where xianlu =". $ _ GET ['select']. you can add multiple conditions by yourself.
Syntax error prompted with. $ _ GET
The new progress is that "select status" is available, but when you open the page for the first time, all content is displayed, and three errors are Prompted. how to modify and open the page without querying, only click query and then query
The complete code is as follows:
Data Query
$ Link = mysql_connect ("localhost", "root", "12345678 ");
If (! $ Link) echo "no connection successful! ";
Else echo "connection successful! ";
Mysql_select_db ("busap", $ link); // select a database
// Control query conditions
$ Q = "SELECT * FROM research where banben like '% {$ _ REQUEST ['banben']} %' AND linename like '% {$ _ REQUEST ['xianlu']} % 'AND zhuangtai like' % {_ _ REQUEST ['zhuangtai']} % 'order by busname asc ";
// Mysql_query ("set names GB2312"); // prevents garbled characters
$ Rs = mysql_query ($ q); // Obtain a dataset
$ Assoc = mysql_num_rows ($ rs); // The number of affected rows. mysql_fetch_assoc was used.
Echo "$ assoc ";
$ Row = mysql_fetch_array ($ rs); // you only need to add this row back.
If (! $ Rs) {die ("Valid result! ");}
?>
Line |
Center No. |
Line |
Vehicle ID |
Transmission mode |
Media version |
Date |
Time |
Status |
Do {?>
|
|
|
|
|
|
|
|
|
Data Query
If ($ _ REQUEST ['submit '])
{
$ Link = mysql_connect ("localhost", "root", "12345678 ");
If (! $ Link) echo "no connection successful! ";
Else echo "connection successful! ";
Mysql_select_db ("busap", $ link); // select a database
// Control query conditions
$ Q = "SELECT * FROM research where banben like '% {$ _ REQUEST ['banben']} %' AND linename like '% {$ _ REQUEST ['xianlu']} % 'AND zhuangtai like' % {_ _ REQUEST ['zhuangtai']} % 'order by busname asc ";
// Mysql_query ("set names GB2312"); // prevents garbled characters
$ Rs = mysql_query ($ q); // Obtain a dataset
$ Assoc = mysql_num_rows ($ rs); // The number of affected rows. mysql_fetch_assoc was used.
Echo "$ assoc ";
$ Row = mysql_fetch_array ($ rs); // you only need to add this row back.
If (! $ Rs) {die ("Valid result! ");}
}
?>
Line |
Center No. |
Line |
Vehicle ID |
Transmission mode |
Media version |
Date |
Time |
Status |
Do {?>
|
|
|
|
|
|
|
|
|
$ Q = "SELECT * FROM research where banben like '% {$ _ REQUEST ['banben']} %' AND linename like '% {$ _ REQUEST ['xianlu']} % 'AND zhuangtai like' % {_ _ REQUEST ['zhuangtai']} % 'order by busname asc ";
Make judgments on $ _ REQUEST ['banben'], $ _ REQUEST ['xianlu'], $ _ REQUEST ['zhuangtai ']
For example:
$ Sqlstr = "";
If (! Empty ($ _ REQUEST ['banben']) {
$ Sqlstr = "and banben like '% {$ _ REQUEST ['banben']} % '";
}
If (! Empty ($ _ REQUEST ['xianlu']) {
$ Sqlstr. = "linename like '% {$ _ REQUEST ['xianlu']} % '";
}
Similarly, $ _ REQUEST ['zhuangtai']
$ Q = "SELECT * FROM research where 1 = 1 $ sqlstr order by busname asc ";
If (! Empty ($ _ REQUEST ['xianlu']) {
$ Sqlstr. = "and linename like '% {$ _ REQUEST ['xianlu']} % '";
}
Now the problem is basically solved, but an error is generated, but it is not delayed. how can this problem be left blank?
The code for Line 2 is:
The complete code is as follows:
Data Query
If ($ _ REQUEST ['submit ']! = "")
{
$ Link = mysql_connect ("127.0.0.1", "root", "12345678 ");
If (! $ Link) echo "no connection successful! ";
Else echo "connection successful! ";
Mysql_select_db ("busap", $ link); // select a database
// Control query conditions
$ Q = "SELECT * FROM research where banben like '% {$ _ REQUEST ['banben']} %' AND linename like '% {$ _ REQUEST ['xianlu']} % 'AND zhuangtai like' % {_ _ REQUEST ['zhuangtai']} % 'order by busname asc ";
// Mysql_query ("set names GB2312"); // prevents garbled characters
$ Rs = mysql_query ($ q); // Obtain a dataset
$ Assoc = mysql_num_rows ($ rs); // The number of affected rows. mysql_fetch_assoc was used.
Echo "$ assoc ";
$ Row = mysql_fetch_array ($ rs); // you only need to add this row back.
If (! $ Rs) {die ("Valid result! ");}
}
?>
Line |
Center No. |
Line |
Vehicle ID |
Transmission mode |
Media version |
Date |
Time |
Status |
Do {?>
|
|
|
|
|
|
|
|
|
Mysql_fetch_array. you can add a judgment.
How to add judgment? no, new guy.