How does the MySQL statement receive an array?

Source: Internet
Author: User
$sql = $empire->query ("Select Userid,agentid,username from member where Agentid= '". $user [UserID]. "' GROUP by UserID ') ;
while ($r = $empire->fetch ($sql))/* Get the records in the result set line by row, get the array row*/
{
$array []= $r;//Accept result set
}

Echo '
';
Print_r ($array);//print array No problem, it's an array.
Echo '
';

I would like to pass the above query $array this array to the following MySQL statement, what should be done. The group by UserID is used to classify, and the following MySQL statement is querying the database again, then classifying it according to the results categorized above.

$sql 2= $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 arrays
Array_keys ($array) only $array the first dimension subscript (0,1,2,3 ...).

$array Two-dimensional arrays
Array_keys ($array) only $array the first dimension subscript (0,1,2,3 ...).

How should I write this statement?
There is data in the while loop, but in the first statement there is no data $array.

What the hell do you want?
It's not going to work that hard.

What the hell do you want?
It's not going to work that hard.


This is the second query to connect the statement, so that you can query, I want to become a paragraph of the statement
Select UserID from member where Agentid in (select UserID from member where agentid= ' $user [userid] ' GROUP by userid) group by UserID

The second query results according to the first query classification, the second can write this statement, but the third query how to write, how long the statement ah

The results of the third query are categorized according to 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.