Thankphp inside the double loop how to write

Source: Internet
Author: User
$left _type = M (' type ')->where ("' pid ' = ' 2 '")->order (' Order ' desc, ' ID ' desc ')->limit (0,10)->select ();

foreach ($left _type as $v) {    $left _goods = M (' goods ')->where ("' pid ' = ' $v [id] ')->order (' Order ' desc, ' id ') Desc ')->limit (0,10)->select ();}


Probably means there are two tables, type tables and goods tables, the type table is the parent table of the goods table, and the ID field in the Type table corresponds to the PID field in the Goods table.
What I want to do now is to loop out the categories in the Type table and then loop the contents of the corresponding goods table under each category.
But I didn't use thankphp before, I don't know how to write it. The top one must be wrong, I just write what I mean.

Ask the great God to write a demo I see, thank you.


Reply to discussion (solution)

$result =m (' goods ')->join (' Right join goods on goods.pid = Type.id ')->select ();
foreach ($result as $key = = $v) {
$value [$v [' pid ']][$key] [' Goodsname ']= $v [' Goodsname '];
.. goods to fetch the content
}


The page shows the words with two volist loops can be done


$type _list = M ("type")->where ()->order ()->limit ()->select (); foreach ($type _list as $key = + $val) {   $type _list[' items '] = M ("Goods")->where ("pid={$val [' ID ']}")->select ();

 
  
  
  • {$vo. Title}
    • {$it. Name}

Maybe that's what you want.
  • 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.