修改 MySQL连接方式为PDO

This commit is contained in:
LyLme 2022-03-12 15:33:19 +08:00
parent 9cf32ee429
commit 552c3cc6f4
1 changed files with 49 additions and 33 deletions

View File

@ -1,26 +1,41 @@
<?php
mysqli_query($con,'set names utf8');
$links = mysqli_query($con, "SELECT * FROM `lylme_links`"); // 获取网站
$groups = mysqli_query($con,"SELECT * FROM `lylme_groups` ORDER BY `group_order` ASC"); // 获取分类
// +----------------------------------------------------------+
// | LyLme Spage |
// +----------------------------------------------------------+
// | Copyright (c) 2022 LyLme |
// +----------------------------------------------------------+
// | File: list.php |
// +----------------------------------------------------------+
// | Authors: LyLme <admin@lylme.com> |
// | date: 2022-3-12 |
// +----------------------------------------------------------+
$links = $DB->query("SELECT * FROM `lylme_links`"); // 获取网站
$groups = $DB->query("SELECT * FROM `lylme_groups` ORDER BY `group_order` ASC"); // 获取分类
$i = 0;
while($group = mysqli_fetch_assoc($groups)) { //循环所有分组
$group_links = mysqli_query($con,"SELECT * FROM `lylme_links` WHERE `group_id` = ".$group["group_id"]);
$link_num=mysqli_num_rows($group_links); // 获取返回字段条目数量
while ($group = $DB->fetch($groups)) { //循环所有分组
$sql = "SELECT * FROM `lylme_links` WHERE `group_id` = " . $group['group_id'];
$group_links = $DB->query($sql);
$link_num = $DB->num_rows($group_links); // 获取返回字段条目数量
echo '<ul class="mylist row"><li class="title">' . $group["group_icon"] . '<sapn>' . $group["group_name"] . '</sapn></li>'; //输出分组图标和标题
if($link_num==0){echo '</ul>'."\n" ;$i = 0; continue;}
while($link = mysqli_fetch_array($group_links)) { // 循环每个链接
if ($link_num == 0) {
echo '</ul>' . "\n";
$i = 0;
continue;
}
while ($link = $DB->fetch($group_links)) { // 循环每个链接
// 返回指定分组下的所有字段
if ($link_num > $i) {
$i = $i + 1;
echo "\n" . '<li class="col-3 col-sm-3 col-md-3 col-lg-1"><a rel="nofollow" href="' . $link["url"] . '" target="_blank">';
if ($link["icon"]=='') {echo '<img src="/assets/img/default-icon.png" alt="默认'.$link["name"].'" />'; }
else if (!preg_match("/^<svg*/", $link["icon"])) {
echo '<img src="'.$link["icon"].'" alt="'.$link["name"].'" />'; }
else{echo $link["icon"];}
if ($link["icon"] == '') {
echo '<img src="/assets/img/default-icon.png" alt="默认' . $link["name"] . '" />';
} else if (!preg_match("/^<svg*/", $link["icon"])) {
echo '<img src="' . $link["icon"] . '" alt="' . $link["name"] . '" />';
} else {
echo $link["icon"];
}
echo '<span>' . $link["name"] . '</span></a></li>';
//输出图标和链接
}
@ -29,8 +44,9 @@ if($link_num==0){echo '</ul>'."\n" ;$i = 0; continue;}
echo '</ul>' . "\n"; //输出分类结束标签
$i = 0;
break; //重置$i为0跳出当前循环
}
}
}
mysqli_close($con);
$DB->close();
?>