Table of Contents
ThinkPHP implements secondary loop reading method, thinkphp implements reading
How to loop and insert multiple pieces of data in THINKPHP
How to output foreach double loop in ThinkPHP template
Home Backend Development PHP Tutorial ThinkPHP implements secondary loop reading method, thinkphp implements reading_PHP tutorial

ThinkPHP implements secondary loop reading method, thinkphp implements reading_PHP tutorial

Jul 13, 2016 am 10:15 AM
thinkphp read

ThinkPHP implements secondary loop reading method, thinkphp implements reading

The example in this article describes how ThinkPHP implements secondary loop reading. Share it with everyone for your reference. The specific implementation method is as follows:

Copy code The code is as follows:

$Category = D('Category')->where('category_pid=0')->findAll();
//dump($Category);
if(!empty($Category)){ //Judge whether level one is empty
foreach($Category as $key=>$value){ //Loop reading
$pid = $value['category_id'];//Field assignment
$Category[$key]['child'] = D('Category')->where("category_pid =$pid")->select();
//echo D('Category')->getLastSql(); //How to print the sql statement
}
}
//dump($Category);
$this->assign('Category',$Category);//Map value

I hope this article will be helpful to everyone’s ThinkPHP framework programming.

How to loop and insert multiple pieces of data in THINKPHP

The way you write the array is too weird. Generally, no one would write data like this. We would write like this:
$data = array( 0 => array( 'id'=>1, 'cate_id'=>1, 'coo_name'=>111 ), 1 => array( 'id'=>2, 'cate_id'=>2, 'coo_name'=>222 )); Of course, your array can also be inserted in a loop: first convert the first id into an array, and then use foreach loop Insert

How to output foreach double loop in ThinkPHP template

ThinkPHP template usage:

{$vo.id}
{$vo.name}
After getting this variable in the php page, $jgbh, $this->display('index'); This is the output of the page.
Just write the code in the html page.

{$vo.ip}
{$vo.khname}

ThinkPHP is a It is an open source framework. You can first download the user manual on the official website and look at the examples in order to learn it better and become familiar with its usage.
Hope it helps you

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/904922.htmlTechArticleThinkPHP implements two-level loop reading, thinkphp implements reading. This article describes the example of ThinkPHP implementing two-level loop reading. method of taking. Share it with everyone for your reference. The specific implementation methods are as follows...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to run thinkphp project How to run thinkphp project Apr 09, 2024 pm 05:33 PM

To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

How to read txt file correctly using pandas How to read txt file correctly using pandas Jan 19, 2024 am 08:39 AM

How to use pandas to read txt files correctly requires specific code examples. Pandas is a widely used Python data analysis library. It can be used to process a variety of data types, including CSV files, Excel files, SQL databases, etc. At the same time, it can also be used to read text files, such as txt files. However, when reading txt files, we sometimes encounter some problems, such as encoding problems, delimiter problems, etc. This article will introduce how to read txt correctly using pandas

Practical tips for reading txt files using pandas Practical tips for reading txt files using pandas Jan 19, 2024 am 09:49 AM

Practical tips for reading txt files using pandas, specific code examples are required. In data analysis and data processing, txt files are a common data format. Using pandas to read txt files allows for fast and convenient data processing. This article will introduce several practical techniques to help you better use pandas to read txt files, along with specific code examples. Reading txt files with delimiters When using pandas to read txt files with delimiters, you can use read_c

There are several versions of thinkphp There are several versions of thinkphp Apr 09, 2024 pm 06:09 PM

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

Example of reading and writing CSV files using OpenCSV in Java Example of reading and writing CSV files using OpenCSV in Java Dec 20, 2023 pm 01:39 PM

Example of using OpenCSV to read and write CSV files in Java. CSV (Comma-SeparatedValues) refers to comma-separated values ​​and is a common data storage format. In Java, OpenCSV is a commonly used tool library for reading and writing CSV files. This article will introduce how to use OpenCSV to implement examples of reading and writing CSV files. Introducing the OpenCSV library First, you need to introduce the OpenCSV library to

How to run thinkphp How to run thinkphp Apr 09, 2024 pm 05:39 PM

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

How to install thinkphp How to install thinkphp Apr 09, 2024 pm 05:42 PM

ThinkPHP installation steps: Prepare PHP, Composer, and MySQL environments. Create projects using Composer. Install the ThinkPHP framework and dependencies. Configure database connection. Generate application code. Launch the application and visit http://localhost:8000.

Which one is better, laravel or thinkphp? Which one is better, laravel or thinkphp? Apr 09, 2024 pm 03:18 PM

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

See all articles