In the Thinkphp3.2 template, data from different tables must be used in the same foreach. What should I do?

Source: Internet
Author: User
I saw a piece of Thinkphp code for Weibo development, but I didn't understand it in some places: I. Code in the Controller: {code...} homepage view * functionIndex () {code...} 2. Code in the View: {code...} "focuses on this: the user's profile picture $ V. face does not know...

I saw a piece of Thinkphp code for Weibo development, but I didn't understand it in some places:
I. Code in the controller:

/*
    • Homepage View
      */

    1. Function Index (){

      // P (S ('usermsg '. session ('uid'); // replace_weibo ('adsf '); // p (C ('filter'); $ db = D ('weibo '); // obtain the ID of the current user and the ID of all the followers of the current user $ uid = array (session ('uid '));//???? $ Where = array ('fans '=> session ('uid'); if (isset ($ _ GET ['gid']) {$ gid = I ('gid', '', 'intval'); $ where ['gid'] = $ gid; $ uid = '';} $ result = M ('follow')-> where ($ where)-> field ('follow')-> select (); if ($ result) {foreach ($ result as $ v) {$ uid [] = $ v ['follow'] ;}// combine WHERE conditions, the condition is that the ID of the current user and the ID of the friend that the current user is interested IN $ where = array ('uid' => array ('in', $ uid )); // can the where condition be a two-dimensional array? // The total number of statistical data records, used for paging $ count = $ db-> where ($ where)-> count (); // query the total number of records meeting the requirements $ Page = new \ Think \ Page ($ count, 20 ); // instantiate the total number of incoming records and the number of records displayed on each page (20) // perform paging data query. Note that the parameters of the limit Method must use the property $ limit = $ Page-> firstRow of the Page class. ','. $ Page-> listRows; $ Page-> setConfig ('Theme ', "% TOTAL_ROW % records % FIRST % UP_PAGE % NOW_PAGE %/% TOTAL_PAGE % DOWN_PAGE % END %"); $ Page-> setConfig ('prev ', 'previous page'); $ Page-> setConfig ('Next', 'next page'); // read all Weibo Posts $ result = $ db-> getAll ($ where, $ limit); // The getAll () method is the // p ($ result) in the drive expansion; $ this-> page = $ Page-> show (); // display the output by PAGE $ this-> weibo = $ result; $ this-> display ();}

      II. Code in the View:

    
          
       
                    
        

    /Uploads/Face/{$ v. face} /Public/Images/noface.gif"Width = '50' height = '50'/>

    "
    The focus is on this: the user's profile picture $ V. face does not know where it comes from.
    The weibo table does not have the face column, and the Code does not read the information in another table,
    Its weibo table structure is as follows:

    The profile picture information may be from this table:

    However, in the homepage table, only face50 face80 face180 is used, but not the face column.

    How does one put data from different tables in the same foreach for processing?

    Source code from: https://github.com/milkbobo/Thinkphp3.2.3-weibo

    Reply content:

    I saw a piece of Thinkphp code for Weibo development, but I didn't understand it in some places:
    I. Code in the controller:

    /*
    • Homepage View
      */

    1. Function Index (){

      // P (S ('usermsg '. session ('uid'); // replace_weibo ('adsf '); // p (C ('filter'); $ db = D ('weibo '); // obtain the ID of the current user and the ID of all the followers of the current user $ uid = array (session ('uid '));//???? $ Where = array ('fans '=> session ('uid'); if (isset ($ _ GET ['gid']) {$ gid = I ('gid', '', 'intval'); $ where ['gid'] = $ gid; $ uid = '';} $ result = M ('follow')-> where ($ where)-> field ('follow')-> select (); if ($ result) {foreach ($ result as $ v) {$ uid [] = $ v ['follow'] ;}// combine WHERE conditions, the condition is that the ID of the current user and the ID of the friend that the current user is interested IN $ where = array ('uid' => array ('in', $ uid )); // can the where condition be a two-dimensional array? // The total number of statistical data records, used for paging $ count = $ db-> where ($ where)-> count (); // query the total number of records meeting the requirements $ Page = new \ Think \ Page ($ count, 20 ); // instantiate the total number of incoming records and the number of records displayed on each page (20) // perform paging data query. Note that the parameters of the limit Method must use the property $ limit = $ Page-> firstRow of the Page class. ','. $ Page-> listRows; $ Page-> setConfig ('Theme ', "% TOTAL_ROW % records % FIRST % UP_PAGE % NOW_PAGE %/% TOTAL_PAGE % DOWN_PAGE % END %"); $ Page-> setConfig ('prev ', 'previous page'); $ Page-> setConfig ('Next', 'next page'); // read all Weibo Posts $ result = $ db-> getAll ($ where, $ limit); // The getAll () method is the // p ($ result) in the drive expansion; $ this-> page = $ Page-> show (); // display the output by PAGE $ this-> weibo = $ result; $ this-> display ();}

      II. Code in the View:

    
          
       
                    
        

    /Uploads/Face/{$ v. face} /Public/Images/noface.gif"Width = '50' height = '50'/>

    "
    The focus is on this: the user's profile picture $ V. face does not know where it comes from.
    The weibo table does not have the face column, and the Code does not read the information in another table,
    Its weibo table structure is as follows:

    The profile picture information may be from this table:

    However, in the homepage table, only face50 face80 face180 is used, but not the face column.

    How does one put data from different tables in the same foreach for processing?

    Source code from: https://github.com/milkbobo/Thinkphp3.2.3-weibo

    Index/Home/Model/CommentModel. class. php

    10 'id', 'content', 'time', 'wid', // 'uid ',
    11' _ type' => 'left'
    12 ),
    13 'userinfo' => array (
    14 'username', 'face50' => 'face', 'uid ',
    15 '_ on' => 'comment. uid = userinfo. uid'
    16 ),

    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.