Home>Article>Daily Programming> Implementation method of drop-down list in PHP infinite classification (2) (picture, text + video)
This article’s implementation method ofPHP infinite classification drop-down list menuwill be combined with the previous article [PHP infinite classification (1) data table design method] The example will be explained in detail for everyone.
PHP Unlimited Classificationis actually a technique of classification. Any technique will be very simple as long as we master its implementation principle, and the principle of PHP infinite classification is the principle of recursion.
Relevant knowledge points about recursion are in [How to implement recursive sorting in PHP?】This article has already been introduced, friends who need to know more can refer to it.
As mentioned in the previous article, PHP unlimited classification must be implemented in combination with a database, and this database must have two fields, id and pid. (pid represents the upper level id)
Below we will introduce the implementation method ofPHP unlimited classificationthrough a simple data table mode.
A simple classification data table information is as follows:
PHP infinite classification implementation drop-down listThe code example is as follows:
"; //print_r($rs);//打印方法结果 echo "";
The final effect of this code is as follows:
In the above code, we define a getList method and set the pass Enter three optional parameters, which are a default $pid, a referenced array parameter &$result, and a space character count $spac. Then the variable $link that connects to the database is set as a global variable, mainly so that it can be used normally in this method.
The main idea to achieve the effect of the above picture is to traverse the array in the example. When its parent pid is the same as the top level 0, extract the array name, re-edit it, add the prefix, put it back, and then pass The recursive algorithm then calls itself to complete one recursion. Next time, if there is a pid of the next level, it will continue to be called. In this way, the effect of the above drop-down list can be easily achieved!
This article is about the specific implementation method ofPHP infinite classification drop-down list.
If you want to learn more about PHP, you can follow the PHP Chinese websitePHP Video Tutorial, everyone is welcome to refer to and learn!
The above is the detailed content of Implementation method of drop-down list in PHP infinite classification (2) (picture, text + video). For more information, please follow other related articles on the PHP Chinese website!