So I’m trying to custom code a loop using for_each in WordPress so that it displays a code (city) for each table that has a state name.. my outcome would be like this displayed;
- New York
-- city1
-- city2
-- city3
- New Jersey
-- city1
-- city2
and so on.. in the database (mysql) each entry is placed into a row with table for State and Table for City but in same row…
I’ve tried doing the following but I’m failing in it;
$states = $wpdb->get_row("SELECT * FROM $wpdb->wp_em_locations WHERE location_state=*);
$city = $wpdb->get_row("SELECT * FROM $wpdb->wp_em_locations WHERE location_town=*);
foreach ( $states as $state ) {
echo '$state';
echo '$city';
}
Edited: get_row may not be the best method of gaining this infomration. I am using your context to get this information but this may be the method you are looking for.
Reference: https://codex.wordpress.org/Class_Reference/wpdb#SELECT_Generic_Results