Wordpress query $ wpdb-> get_results ()

I am trying to run mysql_fetch_array through Wordpress. I found out that the best way to do this is explained here: http://codex.wordpress.org/Class_Reference/wpdb#SELECT_Generic_Results

Here is my request below:

$sql = "SELECT * FROM wp_reminders WHERE reminder LIKE '$today'";
$result = $wpdb->get_results($sql) or die(mysql_error());

    foreach( $result as $results ) {

        echo $result->name;
    }

The foregoing does not produce any results, even though the data do exist. Any ideas what I'm doing wrong?

+5
source share
2 answers

The problem was this:

echo $result->name;

it should be:

echo $results->name;
+13
source

The foreach loop and the initial var statement for 'result = $ wpdb → ...' should be the result.

$sql = "SELECT * FROM wp_reminders WHERE reminder LIKE '$today'";
$results = $wpdb->get_results($sql) or die(mysql_error());

    foreach( $results as $result ) {

        echo $result->name;

    }

, get_results(), : ( - )

foreach ( $ofTheMassiveList as $aSingleResult ) {

        echo $aSingleResult->name;

}
+4

All Articles