doubi8383 2016-08-30 16:16
浏览 27

从数据库中检索对象数组

So I am trying to get some information from a database to populate a view. However whenever I try to call this information I always seem to get an undefined value and thus, the view doesn't populate.

I have looked at How do I return the response from an asynchronous call? and make use of the then function as stated to do for angular already, however it did not help me fix what is wrong.

public getMyObject (ownerId: number): Promise<MyObject[]> {
return this.httpClient.post('ObjectGivenownerID.php', `{ownerID: ${ownerId}}`)
    .then(data => {
        console.log(data);
        return data;
    })

The problem is data is always undefined, so when my view calls this to be initialized the array it requires resolves as undefined. I want to ask if the error is in getting the data, or elsewhere? I am fairly new to working with databases and the like so an explanation and a pointer in the right direction would be appreciated more than a "Did it for you" solution. Thanks!

EDIT : PHP Code

function get_owner($owner_id){
  global $conn;
  $sql = "SELECT * FROM MyObject WHERE owner_id = 1";
  $result = $conn->query($sql);

  if ($result->num_rows > 0) {
        // create an array 
    $emparray = array();

        while($row = $result->fetch_assoc()) {

        $MyObject_id = $row["MyObject_id"];
        $MyObject_attachments = list_attachments_by_MyObject($MyObject_id); 
        $row['attachments']= $MyObject_attachments; 

        $emparray[] = $row;
        }
}


echo json_encode($emparray);

return;
}
get_owner(1)
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
    • ¥15 个人网站被恶意大量访问,怎么办
    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 Centos / PETGEM
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制