Hi I am trying to check the page user $id against the id of a row from the wordpress database and if they equal print first_name and family-name information. The code I am trying to use is but I cannot seem to get it to work. `global $wpdb; $result = $wpdb->get_results( "SELECT * FROM wp_lb_person"); if (id == $id) { echo $row->first_name." ".$row->family_name; } else { echo 'Not Working'; }` Any advise or assistance would be appreciate. This code is added to the page via shortcode Regards Warwick
if (id == $id) { what is "id" in this statement ? Also, this $result = $wpdb->get_results( "SELECT * FROM wp_lb_person"); Returns a list of all your persons, yet you don't loop through them ?
Thanks for the prompt reply. id is the row id ie if the row id is equal to the user id variable. If I have left out any code can you point me in the right direction
Untested code: $result = $wpdb->get_results( "SELECT * FROM wp_lb_person"); foreach ($result as $person) { if ($person['id'] == $id) { // Note if this is an object you should use $person->id echo $row->first_name." ".$row->family_name; } }
Obviously echo $row->first_name." ".$row->family_name; should be echo $person->first_name." ".$person->family_name;