It's urgent. I got recursive and depressed. please help me first. my [column] table structure is like this.
Id uid tititile class
1 0 homepage url
2 0 news
3 0 product url
4 3 technology product
5 4 computer product
Now I want to provide an unlimited drop-down list
The recursive method can be used to implement where uid = 0 to start the loop and then get_str ($ row ['id']); recursion
But the problem arises. because my topic has a CLASS field indicating the topic type... url indicating the external link news indicating the news product representing the product topic
First, a level-1 product is an external link type. its lower-level columns are of the product type.
When I publish products in the background, when selecting the owner column, I should only display all the class = prodcut and its subordinates.
Then, we use recursive methods to add the conditional statement where class = 'product' to SQL'
In this case, there is no way to go down recursion... because this condition will show the technology product computer if it is not recursive.
The delivery code I found on the Internet is UID starting from 0 .......... if I add this condition to where class = 'product', the UID of the technology product is 3 or other numbers such as 56789 may be 0.
In this way, there is no way to recursion... nothing is displayed directly... is there any good way to do it? I don't know what I said clearly.
Reply to discussion (solution)
When listing class = prodcut and its subordinates, it does not start from where uid = 0.
The data in your example starts with where uid = 3.
So you should first obtain the start point id and then recursion
When listing class = prodcut and its subordinates, it does not start from where uid = 0.
The data in your example starts with where uid = 3.
So you should first obtain the start point id and then recursion
Could you please help me?, could you help me write a code that requires unlimited classification?
The forum is a place for communication. for code, please turn left to weike.com
function foo($uid=0, $ext='') { $sql = "select * from tbl_name where uid=$uid" . ($uid && $ext ? " and class='$ext'" : ''); $rs = mysql_query($sql); while($row = mysql_fetch_assoc($rs)) { foo($row['id'], $ext); } }
function foo($uid=0, $ext='') { $sql = "select * from tbl_name where uid=$uid" . ($uid && $ext ? " and class='$ext'" : ''); $rs = mysql_query($sql); while($row = mysql_fetch_assoc($rs)) { foo($row['id'], $ext); } }
Function foo ($ uid = 0, $ ext = ''){
$ SQL = "select * from column where uid = $ uid". ($ uid & $ ext? "And class = '$ ext '":'');
$ Rs = mysql_query ($ SQL );
While ($ row = mysql_fetch_assoc ($ rs) {this line reports an error.
Echo $ row ['id'];
Foo ($ row ['id'], $ ext );
}
}
Echo foo (0, "product ");
Brother
What is the error?
I fixed the error.
But this still must start with UID 0 ..
If the UID is empty, class = '$ ext' will return an error.
Foo (3, "product ")
Isn't it starting from below the product?
Product or not
The problem is that this 3 is not fixed.
For example, my topic includes homepage news products and videos.
When I publish a product in the background, only the product column is listed in the optional column/
There may be multiple product columns in the column... for distinguishing the column type, the value in the class field is used. for example, "product" indicates that all columns are product columns.
Can we implement this without recursion?
Now that you try to start from a node, you need to find the node first.
No matter where the node is stored, you can find it based on its unique attribute.
Yes. eldest brother
But I won't start to loop from the node... what should I do? Baidu has a lot of information. it's all recursive.
function foo($uid,$class=''){ if($class==''){ $sql = "select * from table where uid='".$uid."'"; }else{ $sql = "select * from table where uid='".$uid."' and class='".$class."'"; } $query = mysql_query($sql) or die(mysql_error()); while($result = mysql_fetch_assoc($query)){ echo $result['id'].' '.$result['title'].'
'; foo($result['id'],$result['class']); }}foo(0);
Can you recursion from the root node?
What is the difference?
It depends on your needs. I have several posts in the essence area. you can check them first.
Can you recursion from the root node?
What is the difference?
It depends on your needs. I have several posts in the essence area. you can check them first.
I 've helped a lot. I gave it to you.
Later, I used other ideas to solve the problem.