sql concat() 函数解释

用于把两个字段串联起来

types表

id     name  pid  path      

12 男装    0   0,
13 女装    0   0,  
14 领带   12   0,12,
15 西装   12   0,12,

eg:

 $sql = select types.*,concat(path,id) p from types order by p ;

$data = $sql->exec();

echo "

";

print_r($data);


最后输出结果为:

Array
(
    [0] => stdClass Object
        (
            [id] => 12
            [name] => 男装
            [pid] => 0
            [path] => 0,
            [p] => 0,12
        )

    [1] => stdClass Object
        (
            [id] => 14
            [name] => 领带
            [pid] => 12
            [path] => 0,12,
            [p] => 0,12,14
        )


    [3] => stdClass Object
        (
            [id] => 15
            [name] => 西装
            [pid] => 12
            [path] => 0,12,
            [p] => 0,12,15
        )

    [4] => stdClass Object
        (
            [id] => 13
            [name] => 女装
            [pid] => 0
            [path] => 0,
            [p] => 0,13
        )
)

你可能感兴趣的:(mysql)