How does PHP control MySQL multi-condition query?

Source: Internet
Author: User
PHP: how to control MySQL multi-condition query this post was finally edited by liucheng1515 from 2014-10-0615: 55: 06 to create a PHP database query page, you can enter the version number and select the line for query. the selection status cannot be used. the page is as follows. 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 it, that is, how to control MySQL multi-condition query by opening PHP on the page

This post was last edited by liucheng1515 at 15:55:06

A php database query page is created. you can enter the version number and select a line to query the database. the selection status is unavailable, as shown in the following figure,


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.