PHP怎么获取一个分类下面的所有子分类的数据?



  • 数据表结构如下:
    | category | CREATE TABLE category (
    id int(11) NOT NULL DEFAULT '0',
    pid int(11) DEFAULT NULL,
    title varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
    name varchar(50) COLLATE utf8_unicode_ci DEFAULT NULL,
    PRIMARY KEY (id)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci

    问题:

    现在每一个分类都可以是无限级,随便点击一个全部,展现所有当前分类下面的子分类数据。
    比如:点击了食品分类
    逻辑:食品中有水果,蔬菜,水果里有苹果,香蕉,蔬菜里有西蓝花,白菜,等等。
    点击食品后,怎么把苹果,香蕉,西蓝花,白菜的所有数据展现出来?

    也就是说,不管点击哪个分类,都把当前分类下面的所有子分类下面的数据都返回。

    请问怎么搞呢?(PHP)


Log in to reply
 

最新帖子

最新内容

  • S

    You can use

    <?php { AddLog("anypage.php","reason",ERR_ERROR); } ?>

    or if you want to print that statement in an log you can use

    AddLog("anypage.php","string: ".$string,ERR_DEBUG_LOW);

    read more
  • S

    You can use:

    <?php echo '<script>console.log("debug log")</script>'; ?>

    read more
  • S

    I use cakephp so I use:

    $this->log(YOUR_STRING_GOES_HERE, 'debug');

    read more
  • S

    I have used many of these, but since I usually need to debug when developing, and since I develop on localhost, I have followed the advice of others and now write to the browser's JavaScript debug console (see http://www.codeforest.net/debugging-php-in-browsers-javascript-console).

    That means that I can look at the web page which my PHP is generating in my browser & press F12 to quickly show/hide any debug trace.

    Since I am constantly looking at the developer tools for debugger, CSS layout, etc, it makes sense to look at my PHP loggon there.

    If anyone does decide to us that code, I made one minor change. After

    function debug($name, $var = null, $type = LOG) {

    I added

    $name = 'PHP: ' . $name;

    This is because my server side PHP generates HTML conatining JavaScript & I find it useful to distinguish between output from PHP & JS.

    (Note: I am currently updating this to allow me to switch on & off different output types: from PHP, from JS, and database access)

    read more
  • S

    This a great tool for debugging & logging php: PHp Debugger & Logger

    It works right out of the box with just 3 lines of code. It can send messages to the js console for ajax debugging and can replace the error handler. It also dumps information about variables like var_dump() and print_r(), but in a more readable format. Very nice tool!

    read more

推荐阅读