php 中使用 sql 调用其他 mysql 数据库输出内容并排序

毒药      208阅读

//调用cms数据库内容 开始
$servername = "localhost";//MySQL默认为localhost,端口号3306
$username = "iiduyao11";
$password = "14ju688";
$dbname = "iiduyao11";

// 创建连接
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("连接失败: " . $conn->connect_error);
}

$sql = "SELECT titleurl,title,onclick FROM phome_ecms_news order by onclick desc limit 20";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    
    // 输出数据
        echo'<div class="sider-box">
    <div class="sider-box-title"><i class="fa fa-angle-double-right"></i> 推荐阅读</div>
    <div class="sider-box-content">
        
        <ul>';
    while($row = $result->fetch_assoc()) {
     
     echo'<li><a href="',$row['titleurl'],'" >',$row['title'],'</a><li>';

        
    }
    
    echo'</ul>
         <div class="c"></div>
         </div>
         </div>';
} 

else {
    echo "";
    

}
$conn->close();
//调用cms数据库内容 结束

   208阅读

<?php
header("Content-type:text/html;charset=utf-8");
$servername = "服务器地址";//MySQL默认为localhost,端口号3306
$username = "用户名";
$password = "密码";
$dbname = "数据库名称";

// 创建连接
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("连接失败: " . $conn->connect_error);
}

$sql = "SELECT titleurl,title,onclick FROM phome_ecms_news order by onclick desc limit 20";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // 输出数据
    while($row = $result->fetch_assoc()) {
        echo $row["title"]. " 列名2: " . $row["titleurl"]."<br>";
    }
} else {
    echo "0 结果";
}
$conn->close();
?>

毒药   161.3天前
1
登录 后发表评论