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.
wpdb
‘sget_results
method takes an optional second argument that lets you specify how the data is returned. The default return is an object. But you can also set it to…(from the codex)
You probably want
ARRAY_A
.Unfortunately,
wpdb
doesn’t allow you to “stream in” results like you’re doing, so you’ll need to use a foreach loop.