搜尋

首頁  >  問答  >  主體

如何在一個php中讀取兩個表中的資料求破


<?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(  1Name   'PersonalName'=$Name'$ 'AddPet_PetName_b'=>$row['AddPet_PetName_b'],   'IssueText'=>$row['IssueText'],   'Like'=>$點['Like']
    'Like'=>$ /ike']

    . $arr1[]=$arr;    }}else {    echo "讀取成功";}echo json_encode($arr1);$conn->close();?>###
phantomphantom1831 天前1069

全部回覆(1)我來回復

  • 卢小强

    卢小强2019-11-20 09:10:34

    什麼意思?下次貼程式碼,截圖貼,如果是想聯表查用join,如果是兩個無關聯的表就查2次唄 https://www.runoob.com/mysql/mysql-join.html  這是聯表查的教學

    回覆
    0
  • 取消回覆