I have the feeling that the answer to my problem is going to be very simple. I have written the following code to access a table that I have loaded into my WordPress database. I can run the query in phpMyAdmin. It runs as expected. I have tried everything that I found in an attempt to get it to work.
My Function:
function plcoa_email_address_list () {
global $wpdb;
$user_count = $wpdb->get_var( "SELECT COUNT(*) FROM tblLots" );
echo "<p>Lot count is " . $user_count . "</p>";
$wpdb->show_errors( true );
$result = $wpdb->get_results($wpdb->prepare("SELECT LotNum FROM tblLots;" ));
$wpdb->print_error();
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo $row["email"] . "<br>";
}
} else {
echo " <br> 0 results";
}
}
function plcoa_short_code( $atts=null, $content=null ){
extract(shortcode_atts(array('id'=>''),$atts));
plcoa_email_address_list ();
}
add_shortcode('listemails','plcoa_short_code');
The result that I get is:
Lot count is 369
WordPress database error: [] SELECT LotNum FROM tblLots;
0 results
$wpdb->prepare
or you'll get warnings in your PHP logs, since you aren't inserting any variables there's nothing to prepare so that part can be removed. Also why is there a;
in the second query?