Ajax返回从数据库中获取两个不同的值

时间:2015-03-12 20:00:40

标签: jquery ajax

我有一个普通的ajax函数,它发布到php页面并从表中返回一些项目。

在我尝试设置用户的FB图像之前,一切都很好。我收到了这个错误:

"error": {
  "message": "Unsupported get request.",
  "type": "GraphMethodException",
  "code": 100
}

在检查Chrome的检查元素时,我发现了一些奇怪的东西。

这是Preview中的Network标签:

active: 1
add_date: "2015-03-11 05:28:10"
fb_id: ...828
first_name: "Fname"
id: 468
item_description: "Desc"
item_title: "Title"
user_id: 62
username: ""

这位于Response

Network标签中
[{"id":468,"user_id":62,"item_title":"Title","item_description":"Desc","active":1,"add_date":"2015-03-11 05:28:10","fb_id":...829,"first_name":"Fname","username":""}]

fb_id之外,其他一切都是相同的。在users表中,它以829结尾。

也许我做错了什么。

编辑**

Ajax

$.ajax({
  type:"post",
  url:"ajax/realpha.php",
  dataType: "json",
  data: { 'tab' : tab },
  success: function(data) {

    $(tab).empty();
    jQuery.each(data, function(i) {
       console.log(data[i].fb_id);
    ');
    });

  }
});

realpha.php

  $selectHome = $ItemTools->selectHome();

  echo json_encode($selectHome);

查询

 public function selectHome() {
    if($q = $this->db->mysqli->prepare("SELECT
            t1.id, t1.user_id, t1.item_title, t1.item_number, t1.item_start, t1.item_description, t1.active, t2.first_name, t2.last_name, t2.fb_id, b.maxbid, b.bids
            FROM
              items t1
            LEFT JOIN
              users t2
            ON
              t1.user_id = t2.id
            LEFT JOIN (
              SELECT item_id, bid, MAX(bid) AS maxbid, COUNT(bid) AS bids
              FROM bids GROUP BY item_id
            ) b
            ON t1.id = b.item_id
            WHERE t1.active = 1
            ORDER BY id DESC")) {
    $q->execute();

    $rows = $this->db->bindResults($q);

    $q->close();

    return $rows;

    }

}

1 个答案:

答案 0 :(得分:1)

您的数据库是否在fb_id表的users字段中包含auto_increment?

显示create table语句可能是一个明智的想法。