[英]Selecting where multiple conditions match SafeMysql
i am trying to make this query work我正在尝试使这个查询工作
$key = $db->getAll("SELECT `key`
FROM `".PREFIX."user_stats`
WHERE `article_id` = ?i
AND `domain` = ?s
AND `userid` = ?i",
$article_id, $domain,$userid);
i use SafeMySql and getAll is Helper function to get all the rows of resultset right out of query and optional arguments我使用 SafeMySql 和 getAll 是 Helper 函数来从查询和可选参数中获取结果集的所有行
i want to echo key where 3 other columns match the input.我想在其他 3 列与输入匹配的地方回显键。
with the above query i get output "Array" nothing else.通过上面的查询,我得到的只是输出“Array”。
The structure of the $key object returned from the database, which you gave in the comments is:从数据库返回的 $key 对象的结构,您在注释中给出的是:
array(1) { [0]=> object(stdClass)#1743 (1) { ["keyy"]=> string(6) "rKSpxf" } }
This is an array with a single element at index 0. This element is an object with a single property "keyy".这是一个在索引 0 处具有单个元素的数组。该元素是一个具有单个属性“keyy”的对象。
Therefore to access the data and output it, you need to write:因此要访问数据并输出它,您需要编写:
echo $key[0]->keyy;
The [0]
references the first index of the array, and the ->keyy
references the "keyy" property of the object in that index. [0]
引用数组的第一个索引, ->keyy
引用该索引中对象的“keyy”属性。
To make clearer what's going on, you could write it longhand like this:为了更清楚地说明发生了什么,你可以这样写:
$obj = $key[0]; //get the object out of the array
$prop = $obj->keyy; //get the property out of the object
echo $prop; //output the value of the property
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.