您的位置:首页 > 编程语言 > PHP开发

php进阶 无限极分类

2014-02-17 10:43 567 查看
通过排序查找出分类

数据库

CREATE TABLE `infinite_classify1` (

  `id` smallint(5) unsigned NOT NULL
AUTO_INCREMENT,

  `catpath` varchar(100) NOT NULL,

  `title` varchar(100) NOT NULL,

  PRIMARY KEY (`id`)

) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;

数据库概览








程序代码

<?php

header("content-type:text/html;charset=utf-8");

mysql_connect('localhost','root','910729') or die('链接数据库失败');

mysql_set_charset('utf8');//设定mysql客户机(php)与mysql服务器之间通信的编码

mysql_select_db('test');

$sql="select id,concat(catpath,'-',id) as abspath,title from
infinite_classify1 order by abspath,id";

$result = mysql_query($sql);

//$arr=array();

//$i=0;

//while ($val=mysql_fetch_assoc($result)){

//   
$arr[$i]=$val;

//   
$i++;

//}

while ($row=mysql_fetch_assoc($result)){

    $space =
str_repeat('  ',count(explode('-',$row['abspath']))-1);

    echo
$space.$row['title'].'<br>';

}

echo '<pre>';

print_r($arr);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: