Skip to main content

Fetch How do I fetch each row as an associative array withusing $wpdb?

Tweeted twitter.com/#!/StackWordPress/status/273230174638723075
Source Link
Mark
  • 351
  • 1
  • 4
  • 15

Fetch array with $wpdb

I am trying to convert this code to use the $wpdb.

$data = array();

$query = "SELECT * FROM videos";
$query_exec = mysql_query($query) or die();

while($row = mysql_fetch_array($query_exec)) {
    if ( $row['video'] == "http://youtu.be/".end(explode('http://youtu.be/',$row['video'])) ) {
            $data[$row['id']] = end(explode('http://youtu.be/', $row['video']));
        } else {
            $data[$row['id']] = end(explode('?v=', $row['video']));
        }   
    }

So I did:

$query = $wpdb->get_results("SELECT * FROM videos");

But how can I fetch the array? Thank you in advance for the help.