取得phpcms网站下所有栏目的内容链接

今天做了一个小功能,就是取得公司网站的所有文章的内容地址,公司网站是用phpcms 做的,感觉还蛮简单的,记录下:

 

<?php

    $conf['DB_USER'] = 'user';

    $conf['DB_PWD'] = 'pwd';

    $conf['DB_NAME'] = 'dbname';

    $conn = mysql_connect('localhost',$conf['DB_USER'],$conf['DB_PWD']);

    if (!$conn) {

    	echo '数据库连接错误!';

    }

    mysql_set_charset('utf8', $conn);        //set charset

    mysql_select_db($conf['DB_NAME']);       //select datebase   

    $sql2 = 'select catid,catname from v9_category';

    $cat = mysql_query($sql2);

    while ($catrow=mysql_fetch_array($cat)) {

    	echo $catrow['catname'].'</br>';

    	$sql = '(select title,url from v9_news where catid='.$catrow["catid"].' order by id desc) 

         UNION (select title,url from v9_product where catid='.$catrow["catid"].' order by id desc)';

    	$result = mysql_query($sql);

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

            echo $row['url']."</br>";         

        }

    }

?>


主要是用到联合查询及双重循环。


 

你可能感兴趣的:(phpcms)