Thinkphp Learning (iv) volist tag advanced application multiple nested loops _php Tutorial

Source: Internet
Author: User
Action Code:

    Public Function Index () {$prod = I ("Get.prod_en"), $id = i ("Get.id", 0, "int"), if ($prod = = "") {$serviceProduct = array ();// Array of multi-loop traversal
The data is saved in two tables, where the $serviceproduct array is initialized by looping $service = M ("Product_class")->order ("oid ASC")->select (); for ($i = 0; $i < count ($service); $i + +) {Array_push ($serviceProduct, Array ("srvname" = $service [$i] ["PC_CN"], "Product" =>m ("Product") Where ("prod_class_id=". $service [$i] ["Pcid"])->order ("oid ASC")->select ());}
If you want to output a variable in a template, you must pass the variable to the template in the controller, and the system provides the Assign method to assign a value to the template variable, regardless of which type of variable is uniformly used assign assignment. $this->assign ("Serviceproduct", $serviceProduct); $this->display ();} Else{if ($id > 0) {$this->display ("detail");} else{$this->assign (' prod_en ', $prod); $clsList = M ("Question_class")->order ("oid ASC")->select (); $this- >assign (' clslist ', $clsList); $qusList = M ("question")->order ("oid ASC")->select (); $this->assign (' Quslist ', $qusList); $this->display ("list");}}
Template code:

 
  
  
   
  
{$sp. Srvname}
{$pd. prod_cn}
|
When using multiple nested loops, you need to specify a key value for each volist by
 
  
Determines whether the last element in the array.


http://www.bkjia.com/PHPjc/767112.html www.bkjia.com true http://www.bkjia.com/PHPjc/767112.html techarticle Action Code: Public Function Index () {$prod = I ("Get.prod_en"), $id = i ("Get.id", 0, "int"), if ($prod = = "") {$serviceProduc t = array ();//The array of multiple loops traversed//data saved in ...

  • 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.