您的位置:首页技术文章
文章详情页

如何在一个php中读取两个表中的数据求破

【字号: 日期:2022-06-07 15:59:51浏览:82作者:猪猪

问题描述

<?phpheader("Content-Type: text/html;charset=utf-8");$servername = "localhost";$username = "root";$password = "168168";$dbname = "mypet"; //数据库名// 创建连接$conn = new mysqli($servername, $username, $password, $dbname);$conn->query('set names utf8');// Check connectionif ($conn->connect_error) { die("连接失败: " . $conn->connect_error);} $sql = "SELECT * FROM `user`";// $sql = "SELECT * FROM `mypet`";// $sql = "SELECT * FROM `ggbond`";//查询语句$result = $conn->query($sql);$arr=Array();$arr1=Array();if ($result->num_rows > 0) { // 输出数据 while($row = $result->fetch_assoc()) {$arr=array( 'PersonalName'=>$row['PersonalName'] 'AddPet_PetName_b'=>$row['AddPet_PetName_b'], 'IssueText'=>$row['IssueText'], 'Like'=>$row['Like']); //查询项目$arr1[]=$arr; }}else { echo "读取成功";}echo json_encode($arr1);$conn->close();?>

问题解答

回答1:

什么意思?下次贴代码,截图贴,如果是想联表查用join,如果是两个无关联的表就查2次呗 https://www.runoob.com/mysql/mysql-join.html 这是联表查的教程

相关文章: