I write this about why the PHP background interface can only return one piece of data to the database. I want to return all the data that matches the uphonenumber.

<?php
    header("Content-Type:application/json;charset=UTF-8");
    $uphonenumber = $_POST["phonenumber"];//post
    $json = "";
    $data = array();
    include("init.php");//
    
    //$sql = "SELECT * FROM yffice_project where uphonenumber = $uphonenumber";
    $sql = "SELECT * FROM yffice_project where uphonenumber = $uphonenumber";
    mysql_query("set names utf8");
    $result = mysql_query($sql);//sql
    if($result){
    //echo "";
    while ($row = mysql_fetch_array($result))
    {
    $data["uid"]=$row["uid"];
    $data["pcontent"]=$row["pcontent"];
    $data["src"]=explode(",",$row["ppic"]);
    $data["pdate"]=$row["pdate"];
    $data["pweek"]=$row["pweek"];
    $data["pweather"]=$row["pweather"];
    }
    $json=json_encode($data);
    echo $json;
    }else{
    echo "";
    }
    mysql_close();//
?>
Php
Feb.28,2021

there is a problem with the assignment in your while loop, and the assignment to the same key name is repeated all the time.
the correct one should be:

$data[] = [
    'uid'      => $row["uid"],
    'pcontent' => $row["pcontent"],
    'src'      => explode(",",$row["ppic"]),
    'pdate'    => $row["pdate"],
    'pweek'    => $row["pweek"],
    'pweather' => $row["pweather"]
];

this form;


there is a problem with loop writing. If you write like this, the current data will overwrite the previous data, and only the last piece of data will be returned

.
Menu