Here’s your problem:
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$result
is not a mysqli_result
object, it’s literally the results of the query. Since you never passed a second parameter to the get_results
method specifying what format you wanted them in, it’ll assume "OBJECT"
, so the correct usage would be:
$results = $wpdb->get_results("SELECT * FROM tblLots" );
if ( !empty( $results ) ) {
// output data of each row
foreach ( $results as $row ) {
echo $row['email'];
Notice I also corrected an error in the SQL statement, you only asked the database for the LotNum
field, then tried to grab the email expecting a full database row, when you only asked for a single column
Notice as well that all of this is detailed in the codex and in the dev hub, on the official wp.org docs