2015-12-13
展开全部
<?php
$sql = "SELECT * FROM `url_message` ORDER BY url_id DESC";
$stmt = $dbh->prepare($sql);
$stmt->execute();
$allMessage = $stmt->fetchAll(PDO::FETCH_ASSOC); // 数组
/* 查看数组结构 (其实就是看看你的数据库的字段都叫啥)*/
//<a href="https://www.baidu.com/s?wd=print_r&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9Pj0LnjR3njb1uWuhPhuh0AP8IA3qPjfsn1bkrjKxmLKz0ZNzUjdCIZwsrBtEXh9GuA7EQhF9pywdQhPEUiqkIyN1IA-EUBtdnW0kn104PH6LP1n4nWb3PjR" target="_blank" class="baidu-highlight">print_r</a>($allMessage);die;
/* 假设你的数组每一行的数组结构是这样: */
/* url_id=>'1', url_href=>'product.html', url_text=>'产品列表' */
echo '<ul>';
foreach ($allMessage as $one_link) {
$id = $one_link['url_id']; // id
$href = $one_link['url_href']; // 链接
$text = $one_link['url_text']; // 文字
$a = '<a href="'.$href.'" >'.$text.'</a>';
echo '<li class="navbar-frist-menu'.$id.'">'.$a.'</li>';
}
echo '</ul>';
exit;
$sql = "SELECT * FROM `url_message` ORDER BY url_id DESC";
$stmt = $dbh->prepare($sql);
$stmt->execute();
$allMessage = $stmt->fetchAll(PDO::FETCH_ASSOC); // 数组
/* 查看数组结构 (其实就是看看你的数据库的字段都叫啥)*/
//<a href="https://www.baidu.com/s?wd=print_r&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9Pj0LnjR3njb1uWuhPhuh0AP8IA3qPjfsn1bkrjKxmLKz0ZNzUjdCIZwsrBtEXh9GuA7EQhF9pywdQhPEUiqkIyN1IA-EUBtdnW0kn104PH6LP1n4nWb3PjR" target="_blank" class="baidu-highlight">print_r</a>($allMessage);die;
/* 假设你的数组每一行的数组结构是这样: */
/* url_id=>'1', url_href=>'product.html', url_text=>'产品列表' */
echo '<ul>';
foreach ($allMessage as $one_link) {
$id = $one_link['url_id']; // id
$href = $one_link['url_href']; // 链接
$text = $one_link['url_text']; // 文字
$a = '<a href="'.$href.'" >'.$text.'</a>';
echo '<li class="navbar-frist-menu'.$id.'">'.$a.'</li>';
}
echo '</ul>';
exit;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询