Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

i want to echo key where 3 other columns match the input.

with the above query i get output "Array" nothing else.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
253 views
Welcome To Ask or Share your Answers For Others

1 Answer

The structure of the $key object returned from the database, which you gave in the comments is:

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".

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.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...