如何在一个php中读取两个表中的数据求破
phantom
phantom 2019-11-18 14:59:48
0
1
1087

<?phpheader("内容类型:text/html;charset=utf-8");$servername = "localhost";$username = "root";$password = "168168";$dbname = “我的宠物”;   //数据库名
//创建连接$conn = new mysqli($servername, $username, $password, $dbname);$conn->query('set names utf8');//检查连接if ($ 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();?>

phantom
phantom

全部回复(1)
卢小强

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

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板