We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

query will only return value of "object"

Development and Programming

Greg Aker's avatar
Greg Aker
6,022 posts
17 years ago
Greg Aker's avatar Greg Aker

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

       
Greg Aker's avatar
Greg Aker
6,022 posts
17 years ago
Greg Aker's avatar Greg Aker

anybody? :red:

Kind of stuck here, and need some help, as I can’t move on until I get this figured out!

Thanks,

-greg

       
Daniel Walton's avatar
Daniel Walton
553 posts
17 years ago
Daniel Walton's avatar Daniel Walton

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.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.