如何访问stdClass变量stdClass对象([max(id)])=> 64) [英] How to access stdClass variables stdClass Object([max(id)])=>64)

查看:84
本文介绍了如何访问stdClass变量stdClass对象([max(id)])=> 64)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要数据库表中的最后一个有效条目,该表将是具有最大主键的行.因此,使用mysqli时,我的查询是从表LIMIT 1中选择SELECT MAX(id)".该查询返回正确的数字(使用print_r()),但我不知道如何访问它.这是主要代码.请注意,$ this-> link引用具有mysqli连接的类.

I need the very last valid entry in a database table which would be the row with the greatest primary key. So using mysqli, my query is "SELECT MAX(id) FROM table LIMIT 1". This query returns the correct number(using print_r()) but I cannot figure out how to access it. Here is the main code. Note that the $this->link refers to class with a mysqli connection.

$q="select max(id) from stones limit 1";
    $qed=$this->link->query($q) or die(mysqli_error());
    if($qed){
        $row=$qed->fetch_object();
        print_r($row);
        echo $lastid=$row;//here is the problem
    }

有效行print_r($ row)回显"stdClass对象([max(id)] => 68)"

The valid line print_r($row) echos out "stdClass Object ( [max(id)] => 68 )"

推荐答案

您需要命名汇总结果.

SELECT MAX(id) AS maxid FROM stones

然后您可以访问$row->maxid之类的值.

Then you can access the value like $row->maxid.

这篇关于如何访问stdClass变量stdClass对象([max(id)])=> 64)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆