无限分类,一起学习吧
今天学习的成果,递归,无限分类,新手入门希望多多指教。 无 ?php//列出分类include '../include.php';session_start(); if(empty($_SESSION['user'])) header('location:login.php');function getList($pid=0,$result=array(),$spac=0){$spac = $spac+4; //
今天学习的成果,递归,无限分类,新手入门希望多多指教。
<?php //列出分类 include '../include.php'; session_start(); if(empty($_SESSION['user'])) header('location:login.php'); function getList($pid=0,&$result=array(),$spac=0) { $spac = $spac+4; //空格补位 $sql = "SELECT * FROM cate where pid = '$pid'"; //选择分类数据库,条件是对比pid $query = mysql_query($sql); while ($row = mysql_fetch_assoc($query)) { //取得数组 # 美化分类,清晰一级和二级分类 $row['catename'] = str_repeat(' ', $spac).'|--'.$row['catename']; $result[] = $row; //传值 getList($row['id'],$result,$spac); } return $result; } function displayCate($pid=0){ $rs = getList($pid); $str=""; $str.="<select name='cate'>"; foreach ($rs as $key => $value) { # 下拉式显示 $str.= "<option>{$value['catename']}</option>"; } return $str.= "</select>"; } echo displayCate(0); ?>
<?php session_start(); if(empty($_SESSION['user'])) header("location:login.php"); include '../include.php'; $sql = "SELECT * FROM cate order by id asc"; $query = mysql_query($sql); ?> <html> <meta http-equiv="content-type" content="text/html" charset="utf8"> <head> <title>添加分类</title> </head> <body> <h1 id="添加分类">添加分类</h1> <hr> <form method="post" action="cate.php"> <table width="600" align="center" border="0" cellpadding="0" cellspacing="1" > <tr> <td width="80">请输入分类</td> <td width="40"><input type="text" name="catename" size="20"></td> <td width="50">分类id</td> <td width="30"><input type="text" name="pid"></td> <td><input type="submit" name="sub" value="提交"></td> </tr> </table> <!-- 方便自己查看做的实时表查看分类 --> <table align="center" border="1"> <h1 id="现有信息表">现有信息表</h1> <hr> <?php while($res = mysql_fetch_array($query)) { ?> <tr> <td>id:</td> <td><?php echo $res['id']; ?></td> <td>分类名称</td> <td><?php echo $res['catename']; ?></td> <td>pid:</td> <td><?php echo $res['pid']; ?></td> <br> </tr> <?php } echo '</table> </form> </body> </html>'; // 实时表到这里结束 //填写分类名称catename,pid if(isset($_POST['sub'])){ $catename = $_POST['catename']; $pid = $_POST['pid']; $table = 'cate'; if(empty($catename)) { echo "分类名不能为空哦"; }else{ cate($table,$catename,$pid);//调用 sql.func.php中的cate分类函数 } } ?>



Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The recursion depth of C++ functions is limited, and exceeding this limit will result in a stack overflow error. The limit value varies between systems and compilers, but is usually between 1,000 and 10,000. Solutions include: 1. Tail recursion optimization; 2. Tail call; 3. Iterative implementation.

Yes, C++ Lambda expressions can support recursion by using std::function: Use std::function to capture a reference to a Lambda expression. With a captured reference, a Lambda expression can call itself recursively.

The recursive algorithm solves structured problems through function self-calling. The advantage is that it is simple and easy to understand, but the disadvantage is that it is less efficient and may cause stack overflow. The non-recursive algorithm avoids recursion by explicitly managing the stack data structure. The advantage is that it is more efficient and avoids the stack. Overflow, the disadvantage is that the code may be more complex. The choice of recursive or non-recursive depends on the problem and the specific constraints of the implementation.

When editing text content in Word, you sometimes need to enter formula symbols. Some guys don’t know how to input the root number in Word, so Xiaomian asked me to share with my friends a tutorial on how to input the root number in Word. Hope it helps my friends. First, open the Word software on your computer, then open the file you want to edit, and move the cursor to the location where you need to insert the root sign, refer to the picture example below. 2. Select [Insert], and then select [Formula] in the symbol. As shown in the red circle in the picture below: 3. Then select [Insert New Formula] below. As shown in the red circle in the picture below: 4. Select [Radical Formula], and then select the appropriate root sign. As shown in the red circle in the picture below:

Tail recursion optimization (TRO) improves the efficiency of certain recursive calls. It converts tail-recursive calls into jump instructions and saves the context state in registers instead of on the stack, thereby eliminating extra calls and return operations to the stack and improving algorithm efficiency. Using TRO, we can optimize tail recursive functions (such as factorial calculations). By replacing the tail recursive call with a goto statement, the compiler will convert the goto jump into TRO and optimize the execution of the recursive algorithm.

A recursive function is a technique that calls itself repeatedly to solve a problem in string processing. It requires a termination condition to prevent infinite recursion. Recursion is widely used in operations such as string reversal and palindrome checking.

Recursive definition and optimization: Recursive: A function calls itself internally to solve difficult problems that can be decomposed into smaller sub-problems. Tail recursion: The function performs all calculations before making a recursive call, which can be optimized into a loop. Tail recursion optimization condition: recursive call is the last operation. The recursive call parameters are the same as the original call parameters. Practical example: Calculate factorial: The auxiliary function factorial_helper implements tail recursion optimization, eliminates the call stack, and improves efficiency. Calculate Fibonacci numbers: The tail recursive function fibonacci_helper uses optimization to efficiently calculate Fibonacci numbers.

Title: Learn the main function in Go language from scratch. As a simple and efficient programming language, Go language is favored by developers. In the Go language, the main function is an entry function, and every Go program must contain the main function as the entry point of the program. This article will introduce how to learn the main function in Go language from scratch and provide specific code examples. 1. First, we need to install the Go language development environment. You can go to the official website (https://golang.org
