In this section we will introduce a simple drop-down menu classification, similar to the following:
|-- Clothing
|-- Men's clothing
|-- Women's clothing
|-- Food
## |-- Staple food
|-- Rice
|-- Non-staple food
First, we need to create a simple database test and Connect<?php $link = mysqli_connect('localhost','username','password','test'); mysqli_set_charset($link,"utf8"); if (!$link) { die("连接失败:".mysqli_connect_error()); } ?>and then create a table class and set the following fields: id: It is unique, type is int, and select the primary key. title: Name, type is varchar, length is 30. pid: classification, type is int.
<?php $SQL ="CREATE TABLE IF NOT EXISTS 'class' ( 'id' int(10) NOT NULL, 'title' varchar(30) NOT NULL, 'pid' int(10) NOT NULL, ) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 "; ?>Then import some test data:
<?php $SQL = "INSERT INTO `class` (`id`, `title`, `pid`) VALUES (1, '服饰', 0), (2, '食品', 0), (3, '女装', 1), (4, '男装', 1), (5, '主食', 2), (6, '副食', 2), (7, '大米', 5);" ?>