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