2

例如,在我的 sql 查询下面。

$query = mysql_query("SELECT COUNT(*) as `box.id`
    from boxes as box 
    left join page_boxes as pbox 
         on box.id=pbox.bid 
         left join page_subcribers as pages 
             on pages.page_id=pbox.page_id 
             left join category_boxes as cbox 
                 on box.id=cbox.bid 
                 left join subcribers as catsb 
                     on cbox.category_id=catsb.cid 
     where pages.uid='".$session_id."' or catsb.uid='".$session_id."' 
     and box.status='".$approval."'")or die (mysql_error());

$row = mysql_fetch_array($query);
$total = $row['id'];

我需要box.id作为该查询的索引$total = $row['id'];,但是当我像这样使用它$total = $row['id'];时出现错误

Notice: Undefined index: id in C:\xampp\htdocs\media\ctrx.php on line 12

我怎样才能得到这个索引 id 值?

4

2 回答 2

1

我想会是$total = $row['box.id'];

于 2013-09-20T19:20:14.617 回答
0

只需删除反引号

      $query = mysql_query("SELECT   COUNT(*) as box.id

或者你可以使用这样的反引号

    $query = mysql_query("SELECT   COUNT(*) as `box`.`id`

但不是表格和列以及反引号

    `box.id`   // <---this wrong
于 2013-09-20T19:19:52.813 回答