Hello:
I’m working on a Plugin and am having problems with a query returning a result other than the value of “object” in EE. I have debugging & display sql queries on, and I know things are being translated correctly. I can run the same query that I see in the sql output on the page in command line/phpmyadmin, and I get the real value. I have also tried hard-coding values into
Can someone please take a peek at this & tell me what I might be doing wrong?
$screenName = $_POST['member_name'];
$userName = $DB->query("SELECT `member_id` FROM `exp_members` WHERE `screen_name` = '".$DB->escape_str($screenName)."'");
$this->return_data .= $userName;
return $this->return_data;
I have tried putting a hard value in for $screenName, and I have even taken the $screenName var complete out of the picture, replacing the $DB->escape_str part with the value I want to search for.
eg:
I’ve tested with usernames of that are a single word, multiple words, and I’ve played with removing backticks, etc. For Instance:
$userName = $DB->query("SELECT member_id FROM exp_members WHERE screen_name = 'John Coltrane'");
// OR
$userName = $DB->query("SELECT member_id FROM exp_members WHERE screen_name = 'Bob'");
And yes, these values DO exist in my database. 😜
Any ideas, I know it’s gotta be something easy =)
Many thanks in advance,
-greg
Hi Greg,
Bit late on this so hopefully you’ve already resolved your issue. In case you haven’t the $DB->query method returns an object containing, amongst other properties, a result array which you can access like so:
$query = $DB->query("SELECT member_id FROM exp_members WHERE screen_name = 'John Coltrane'");
foreach($query->result AS $row)
{
echo $row['member_id']."\n";
}
The above pertains to having multiple rows returned from the query. For a singular result, the returned object from the database class also has another property you might be interested in:
$query = $DB->query("SELECT member_id FROM exp_members WHERE screen_name = 'John Coltrane'");
echo $query->row['member_id'];
Alternatively:
echo $DB->query("SELECT member_id FROM exp_members WHERE screen_name = 'John Coltrane'")->row['member_id'];
hth.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.