I want to put the two arrays of PHP together. please kindly advise-php Tutorial

Source: Internet
Author: User
** Problem: I want to query two pieces of information published by each member from the database and encapsulate {code...} in an array ...} query member information {code ...} ** problem: I want to query the two messages published by each member in the database and encapsulate them in arrays.

$ Userlist contains all the queried users. $ Listinfo contains two pieces of data released by this user. I want to encapsulate a user in this form as an array, and then the user's array contains an array, which contains two pieces of information published by the user: large Array {User group {User product array 1 {} User product array 2 {}}}}**

// Query member information

$ Accompanyinfo = $ this-> db-> from ($ this-> db-> dbprefix ('member '). 'As M2')-> join ($ this-> db-> dbprefix ('Member _ data '). AS A', 'A. uid = m2.uid ', 'left')-> where ('A. service <> ', '')-> where ('A. uid <> ', 1)-> limit ($ start, $ limit)-> get ()-> result_array (); $ userlist = array (); // user $ listinfo = array (); // product foreach ($ accompanyinfo as $ t) {$ a ['uid'] = $ t ['uid']; $ a ['name'] = $ t ['name']; $ a ['sex'] = $ t ['sex']; $ a ['age'] = $ t ['age']; $ a ['status'] = unserialize (stripslashes ($ t ['status']); $ a ['service'] = unserialize (stripslashes ($ t ['service']); $ a ['tx '] = SYS_ATTACHMENT_URL. 'member /'. $ t ['uid']. '/'.{t}'txdz'{.'.jpg'; $ a ['hobby'] = $ t ['hobby']; $ a ['Contact '] = $ t ['Contact']; $ a ['Abstract '] = $ t ['Abstract']; $ a ['seat'] = dr_linkagepos ('address', $ t ['seat'], '', NULL); // query two Products $ list = $ this-> db-> where ('uid', $ a ['uid']) -> where ('catid', 1)-> limit (2)-> order_by ('inputtime desc')-> get ('Dr _ your accompany ') -> result_array (); foreach ($ list as $ s) {$ B ['id'] = $ s ['id']; // information ID $ B ['uid'] = $ s ['uid']; // publisher ID $ B ['catid'] = $ s ['catid']; // topic ID $ B ['title'] = $ s ['title']; // title $ B ['fuudidian '] = dr_linkagepos ('address ', $ s ['fudidian'], '-', NULL); // service location $ B ['peihuxingshi '] = $ s ['peihuxingshi']; // escort form $ B ['chujia '] = $ s ['chujia']; // bid $ B ['tese'] = unserialize (stripslashes ($ s ['tese']); // Features $ B ['teshufuwu'] = $ s ['teshufuwu']; // Special Service $ listinfo [] = $ B ;} $ userlist [] = $ ;}

Reply content:

** Problem: I want to query the two messages published by each member in the database and encapsulate them in arrays.

$ Userlist contains all the queried users. $ Listinfo contains two pieces of data released by this user. I want to encapsulate a user in this form as an array, and then the user's array contains an array, which contains two pieces of information published by the user: large Array {User group {User product array 1 {} User product array 2 {}}}}**

// Query member information

$ Accompanyinfo = $ this-> db-> from ($ this-> db-> dbprefix ('member '). 'As M2')-> join ($ this-> db-> dbprefix ('Member _ data '). AS A', 'A. uid = m2.uid ', 'left')-> where ('A. service <> ', '')-> where ('A. uid <> ', 1)-> limit ($ start, $ limit)-> get ()-> result_array (); $ userlist = array (); // user $ listinfo = array (); // product foreach ($ accompanyinfo as $ t) {$ a ['uid'] = $ t ['uid']; $ a ['name'] = $ t ['name']; $ a ['sex'] = $ t ['sex']; $ a ['age'] = $ t ['age']; $ a ['status'] = unserialize (stripslashes ($ t ['status']); $ a ['service'] = unserialize (stripslashes ($ t ['service']); $ a ['tx '] = SYS_ATTACHMENT_URL. 'member /'. $ t ['uid']. '/'.{t}'txdz'{.'.jpg'; $ a ['hobby'] = $ t ['hobby']; $ a ['Contact '] = $ t ['Contact']; $ a ['Abstract '] = $ t ['Abstract']; $ a ['seat'] = dr_linkagepos ('address', $ t ['seat'], '', NULL); // query two Products $ list = $ this-> db-> where ('uid', $ a ['uid']) -> where ('catid', 1)-> limit (2)-> order_by ('inputtime desc')-> get ('Dr _ your accompany ') -> result_array (); foreach ($ list as $ s) {$ B ['id'] = $ s ['id']; // information ID $ B ['uid'] = $ s ['uid']; // publisher ID $ B ['catid'] = $ s ['catid']; // topic ID $ B ['title'] = $ s ['title']; // title $ B ['fuudidian '] = dr_linkagepos ('address ', $ s ['fudidian'], '-', NULL); // service location $ B ['peihuxingshi '] = $ s ['peihuxingshi']; // escort form $ B ['chujia '] = $ s ['chujia']; // bid $ B ['tese'] = unserialize (stripslashes ($ s ['tese']); // Features $ B ['teshufuwu'] = $ s ['teshufuwu']; // Special Service $ listinfo [] = $ B ;} $ userlist [] = $ ;}

Just change it a bit.

$ Accompanyinfo = $ this-> db-> from ($ this-> db-> dbprefix ('member '). 'As M2')-> join ($ this-> db-> dbprefix ('Member _ data '). AS A', 'A. uid = m2.uid ', 'left')-> where ('A. service <> ', '')-> where ('A. uid <> ', 1)-> limit ($ start, $ limit)-> get ()-> result_array (); $ userlist = array (); foreach ($ accompanyinfo as $ t) {$ a ['uid'] = $ t ['uid']; $ a ['name'] = $ t ['name']; $ a ['sex'] = $ t ['sex']; $ a ['age'] = $ t ['age']; $ a ['status'] = unserialize (stripslashes ($ t ['status']); $ a ['service'] = unserialize (stripslashes ($ t ['service']); $ a ['tx '] = SYS_ATTACHMENT_URL. 'member /'. $ t ['uid']. '/'.{t}'txdz'{.'.jpg'; $ a ['hobby'] = $ t ['hobby']; $ a ['Contact '] = $ t ['Contact']; $ a ['Abstract '] = $ t ['Abstract']; $ a ['seat'] = dr_linkagepos ('address', $ t ['seat'], '', NULL); // query two Products $ list = $ this-> db-> where ('uid', $ a ['uid']) -> where ('catid', 1)-> limit (2)-> order_by ('inputtime desc')-> get ('Dr _ your accompany ') -> result_array (); $ listinfo = array (); // you must initialize foreach ($ list as $ s) here) {$ B ['id'] = $ s ['id']; // information id $ B ['uid'] = $ s ['uid']; // publisher ID $ B ['catid'] = $ s ['catid']; // topic ID $ B ['title'] = $ s ['title']; // Title $ B ['fuwudidian'] = dr_linkagepos ('address', $ s ['fuwudidian'], '-', NULL ); // service location $ B ['peihuxingshi '] = $ s ['peihuxingshi']; // escort form $ B ['chuja'] = $ s ['chuja']; // bid $ B ['tese'] = unserialize (stripslashes ($ s ['tese']); // Features $ B ['teshufuwu'] = $ s ['teshufuwu']; // Special Service $ listinfo [] = $ B ;} $ a ['listinfo'] = $ listinfo; // $ userlist [] = $ ;}

Try $ a ['listinfo'] = $ listinfo;
Without careful consideration, we understand that $ a is the personal data of the current user, and $ listinfo is the array of information published by the current user.

You can get the user publishing information when looping $ userinfo, and then append the obtained information to a custom item in the array, foreach ($ userinfo as $ key => $ ){

$ B = "user published information"; $ userinfo [$ key] ["message"] = $ B;

}
Phone typing replies. it's not surprising that there are typos.

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.