I am trying to run a mysql_fetch_array via Wordpress. I found out the best way to do this is explained here: http://codex.wordpress.org/Class_Reference/wpdb#SELECT_Generic_Results
Here is my query 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 above is not pulling in any results at all, even though the data does exist. Any ideas what I am doing wrong?
the problem was the following:
echo $result->name;
should be:
echo $results->name;
The 'foreach' loop and the initial var statement for 'result = $wpdb->...' should be results.
$sql = "SELECT * FROM wp_reminders WHERE reminder LIKE '$today'";
$results = $wpdb->get_results($sql);
foreach( $results as $result ) {
echo $result->name;
}
The logic behind this is that you would be gathering all results from the get_results() function and then looping through them as such: (read it out loud - the logic is enforced)
foreach ( $ofTheMassiveList as $aSingleResult ) {
echo $aSingleResult->name;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With