How to query and output mysql fields-php Tutorial

Source: Internet
Author: User
Query mysql fields and output table A: idtitle ----------------------------------- 10 test 11 Hello 12 good 13 very good PHP output: PHPcode $ test [title] array (md & gt; test ), array (md & gt; hello), array query mysql fields and output
Table:

Idtitle
---------------------------------
10 tests
11 Hello
12 Good
13 Very good

PHP output:
PHP code
  $ Test ['title'] = array ('MD' => 'test'), array ('MD' => 'Hello '), array ('MD' => ''), array ('MD' => ''),);


If you want to query the mysql database, there is a question about "test, Hello, good, very good" Id value, How should I write mysql Query statements? For example:
SQL code
  SELECT * from a where A. title = "test" or A. title = "Hello" or A. title = "good" or A. title = "very good" limit
Such a query statement can only list matched data in the database. I just want him to output the ID field. what should I do?

------ Solution --------------------
SELECT * from a where A. title in ('test', '') limit

------ Solution --------------------
PHP output is relatively simple.
1. connect to the database.
2. execute select
3. mysql_fetch_array
The following cannot be entered ...... Google by myself
------ Solution --------------------
Although you are not there, I still write it out and give it to me:
$ SQL = "SELECT id, title FROM A where title in ('test', '', '',' ') limit ";
$ Link = mysql_connect ('127. 0.0.1 ', 'MySQL _ user', 'MySQL _ password ');
If (! $ Link ){
Die ('could not connect: '. mysql_error ());
}
Mysql_select_db ("mysql_database", $ link );
Mysql_query ("set names utf8 ");
$ Res = mysql_query ($ SQL );
While ($ info = mysql_fetch_assoc ($ res )){
Echo "the id number of". $ info ['title']. "is". $ info ['id']."
";
}
Over; remember to score !!

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.