Why can't mysql statements receive arrays? -Php Tutorial

Source: Internet
Author: User
Why can't mysql statements receive arrays? $ SQL = $ empire-> query ("select userid, agentid, username from member where agentid = '". $ user [userid]. "'group by userid ");
While ($ r = $ empire-> fetch ($ SQL)/* get records in the result set row by row to get the Array row */
{
$ Array [] = $ r; // accept the result set
}

Echo'
';
Print_r ($ array); // Print the array. the output is an array.
Echo'
';

I want to pass the $ array queried above to the mysql statement below. what should I do. The group by userid is used for classification. the following mysql statement queries the database again, and then classifies the database based on the classification results.

$ Sql2 = $ empire-> query ("select userid, agentid, username from member where agentid in ('. implode ('', array_keys ($ array )). ') group by userid ");


Reply to discussion (solution)

$ Array two-dimensional array
What array_keys ($ array) returns is the subscript of the first dimension of $ array (0, 1, 2, 3 ....)

$ Array two-dimensional array
What array_keys ($ array) returns is the subscript of the first dimension of $ array (0, 1, 2, 3 ....)

How can I write this statement?
There is data in the while loop, but $ array does not have data in the first statement.

What do you want to do?
In this way, the code cannot be hardened.

What do you want to do?
In this way, the code cannot be hardened.


This is the second statement to be connected, so that it can be queried.
Select userid from member where agentid IN (select userid from member where agentid = '$ user [userid] 'group by userid) group by userid

The second query result is classified by the first query. The second query can write statements like this, but how can I write statements for the third query? that's a long statement.

The third query result is classified by the second query

It's done.

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.