Mysql helps solve a problem. thank you.

Source: Internet
Author: User
Mysql experts come in to help solve a problem, thank you // connect to the database $ db = mysql_connect ($ db_host, $ db_user, $ db_passwd) ordie ('cannotconnecttodatabase'); mysql_select_db ($ db_name) o mysql experts come in to help solve a problem. thank you
// Connect to the database
$ Db = mysql_connect ($ db_host, $ db_user, $ db_passwd) or die ('Can not connect to database ');
Mysql_select_db ($ db_name) or die ('No database ');

$ Q31 = "select * from member where sh1 = '$ arr [sh1]' and status = '0' order by id Limit 0, 10 ";
$ R31 = mysql_query ($ q31, $ db );
While ($ a31 = mysql_fetch_array ($ r31 ))
{
$ Id. = "$ a31 [id]";
}

// Among the 10 data records output above, do I need to further compare the IP addresses of the 10 data records with the ID "1005? I cannot write it like this:
$ Data = "1005 ";
Foreach ($ id as $ data)
{
Echo "include ";
} Else {
Echo "does not contain ";
}
// Please help me write the most efficient code. thank you!


------ Solution --------------------
I wrote

/If you want to obtain the data before determining
$ Myid = array ();
While ($ a31 = mysql_fetch_array ($ r31 )){
$ Id = $ a31 ['id'];
$ Myid [] = $ id;
}

Foreach ($ Myid as $ Idvalue ){
If ($ Idvalue = 1005 ){
Echo 'Id list contains 1005 ';
Break;
}
}


If you want to ask a question later, make it clear whether there is an id equal to 1005 or if the $ a31 [id] array contains 1005

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.