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


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;
|improve this answer|||||
  • where do i read this stuff? As i need to insert data later too, and do complex queries on db. I am a starter. – Nofel Oct 13 '14 at 10:10
  • You can see the output_type for get_results on codex, on the link you put on your post. – angoru Oct 13 '14 at 10:16
  • so i need to learn OOP first? – Nofel Oct 13 '14 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 Oct 13 '14 at 11:00
  • "The wordpress core is oop programmed" not completely true. – Pieter Goosen Oct 13 '14 at 11:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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