注:转载自网络,部分功能需优化,可按照此思路操作。
<?php $conf['DB_USER'] = '数据库用户名'; $conf['DB_PWD'] = '数据库密码'; $conf['DB_NAME'] = '数据库名'; $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 表前缀_category'; $cat = mysql_query($sql2); while ($catrow=mysql_fetch_array($cat)) { echo $catrow['catname'].'</br>'; $sql = '(select title,url from 表前缀_news where catid='.$catrow["catid"].' order by id desc) UNION (select title,url from 表前缀_picture where catid='.$catrow["catid"].' order by id desc)'; $result = mysql_query($sql); while ($row=mysql_fetch_array($result)) { echo $row['url']."</br>"; } } ?>
有朋自远方来...评论一下呗O(∩_∩)O