I am trying to make plugin, and i followed codex, i am not a OOP literate, hence i a blank. I tried to run this query
$myrows = $wpdb->get_results( "SELECT question FROM wp_quiz" );

while i tried to echo $myrows but it didn't gave me anything, so i tried to print_r($myrows), which gave me my output with the following prepend text

Array ( [0] => stdClass Object ( [question] => What is the flag color of Pakistan ) )

How can i echo out a proper column from the table, because i just seemed to start.? Do i need to do crash course on OOP before getting into this? What should i know.?

1 Answer 1


By default, wordpress get_results return a numerically array of objects, so to use echo to print your data yo should do something like;

foreach($myrows as $line){
  echo $line->question;
  • where do i read this stuff? As i need to insert data later too, and do complex queries on db. I am a starter.
    – localhost
    Commented Oct 13, 2014 at 10:10
  • You can see the output_type for get_results on codex, on the link you put on your post.
    – angoru
    Commented Oct 13, 2014 at 10:16
  • so i need to learn OOP first?
    – localhost
    Commented Oct 13, 2014 at 10:54
  • The wordpress core is oop programmed so when you call to $wpdb->get_results you are calling method from class... but you can do a lot od stuff just knowing the basics.
    – angoru
    Commented Oct 13, 2014 at 11:00
  • "The wordpress core is oop programmed" not completely true. Commented Oct 13, 2014 at 11:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.