Home Backend Development PHP Tutorial PHP classifies infinite levels into arrays

PHP classifies infinite levels into arrays

Jul 25, 2016 am 09:03 AM

  1. set aa=new classlist
  2. aa.id="id"//Name of the number
  3. aa.classname="classname"//Classification name
  4. aa.pid="pid"// Parent ID name
  5. aa.db_name="class"//Table name
  6. list=aa.arrylist()
  7. ?>
Copy code

Class: classlist

  1. <%
  2. class classlist
  3. private c_id
  4. private c_db_name
  5. private c_pid
  6. private c_classname
  7. public property let id(str)
  8. c_id = str
  9. end property
  10. public property let db_name(str)
  11. c _db_name = str
  12. end property
  13. public property let pid(str)
  14. c_pid = str
  15. end property
  16. public property let classname(str)
  17. c_classname = str
  18. end property
  19. dim list()
  20. dim i,n
  21. Private Sub Class_Initialize() 'Initialize variable
  22. i=0
  23. n=0
  24. End Sub
  25. public function classarry(thisid,pid)'Get the subordinate ID
  26. if pid>0 then
  27. sql="select * from "&c_db_name&" where "&c_pid&"="&thisid
  28. else
  29. sql="select * from "&c_db_name&" where "&c_id&"="&thisid
  30. end if
  31. set rs_c=conn.execute(sql)
  32. n=n+1
  33. do while not rs_c.eof
  34. list(0, i)=rs_c(c_id)' is loaded into the array
  35. list(1,i)=rs_c(c_classname)
  36. list(2,i)=n
  37. 'n=n+1
  38. i=i+1
  39. thisid=classarry (rs_c(c_id),1)' is called recursively here until the last subclass
  40. rs_c.movenext
  41. loop
  42. n=n-1
  43. rs_c.close
  44. end function
  45. public function arrylist()' loops out all root classes
  46. set rs_c=conn.execute("select count("&c_id&") from "&c_db_name)
  47. lenght=rs_c(0)
  48. rs_c.close
  49. redim list(2,lenght)'set array
  50. set rs1=conn.execute(" select "&c_id&" from "&c_db_name&" where "&c_pid&"=0")
  51. do while not rs1.eof
  52. call classarry(rs1(c_id),0)
  53. 'n=1
  54. rs1.movenext
  55. loop
  56. rs1.close
  57. arrylist=list
  58. end function
  59. end class
  60. %>
Copy code

Example test: Table class Field id: automatic number classname: name pid: parent ID File name: test.asp

  1. <%
  2. Set conn=Server.CreateObject("ADODB.connection")
  3. Set Rs = Server.CreateObject( "ADODB.Recordset")
  4. StrDSN = "Driver={Microsoft Access Driver (*.mdb)}; DBQ="
  5. StrDSN = StrDSN & Server.MapPath("test.mdb")
  6. conn.Open strDSN
  7. function ins( num)
  8. str=""
  9. for ii=1 to num
  10. str=str&"|-"
  11. next
  12. ins=str
  13. end function
  14. set aa=new classlist
  15. aa.id="id"
  16. aa.classname= "classname"
  17. aa.pid="pid"
  18. aa.db_name="class"
  19. list=aa.arrylist()
  20. response.write "< td>Category"
  21. for j=0 to ubound(list,2)
  22. response.write ""&list(0,j)&"
  23. "
  24. next
  25. response.write "
  26. IDName
    "&list(1,j)&""&list(2,j)&"
    "
  27. 'response.write list(1,3)
  28. %>
Copy code

Loop results: bbs.it-home.org/code/class/test.asp It can basically meet the usual needs.



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

Video Face Swap

Video Face Swap

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

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)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Explain the concept of late static binding in PHP. Explain the concept of late static binding in PHP. Mar 21, 2025 pm 01:33 PM

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

See all articles