Quantcast
Channel: Topic Tag: MySQL | WordPress.org
Viewing all articles
Browse latest Browse all 5530

JukeBoxWhiz on "what's wrong with this php mysql code?"

$
0
0

Trying to learn how retrieve data from a database for display on a wordpress page.

I'm using the sakila database.

I'm using this to display names:

global $wpdb;  $customers = $wpdb->get_results("SELECT first_name FROM sakila.actor;");
while($row[] = mysql_fetch_array( $customers )){
   echo $row[first_name];
}

Here is the error I get:

Warning: mysql_fetch_array() expects parameter 1 to be resource, array given in C:\xampp\htdocs\wordpress\wp-content\themes\twentyfifteen\db-exp.php on line 28

Isn't $customers an array?

Before I tried this code I was using this:

<?php global $wpdb; $customers = $wpdb->get_results("SELECT first_name FROM sakila.actor;"); print_r($customers); ?>

And it printed out the entire array of first names, but included meta data like Array[0]Penelope Array[1]Arnold... all the way through to the 200th item.

So, I figure there is an array within the variable $customers. So why isn't that a resource?


Viewing all articles
Browse latest Browse all 5530

Trending Articles