About querying the MySQL field and outputting it, how to resolve

Source: Internet
Author: User
About querying the MySQL field and outputting
Table A:

Idtitle
---------------------------------
10 Testing
11 Hello
12 Very good
13 Very good

PHP Output:
PHP Code
  
   $test [' title '] = Array (' MD ' = ' test '), Array (' MD ' =  ' hello '), Array (  ' md ' = = ' very good '),  Array ( ' MD ' = ' very good ');


Ask if you want to query the MySQL database, there are "testing, hello, very good, very good" the ID value, how should MySQL query statements be written? Similar:
SQL Code
  
   SELECT * from A where a.title = "Test" or a.title = "Hello" or a.title = "very good" or a.title = "very good" limit 0,10
Such a query statement, such a statement can only list matching 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 ', ' hello ', ' good ', ' very good ') limit 0,10

------Solution--------------------
It's easier to use PHP output.
1. Connect to the database.
2. Execute Select
3.mysql_fetch_array
The following is not a fight. ..... Own Google is more than
------Solution--------------------
Although you are not in, but I still write, points to me:
$sql = "Select Id,title from A where title in (' Test ', ' hello ', ' good ', ' very good ') limit 0,10";
$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 "title". $info [' title ']. " The ID number is ". $info [' id ']."
";
}
Over; Remember to give points!!
  • 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.