How to make a SQL query
-
Hello.
I need to fill a select with the result of a SQL Query, and I don’t know how. Can you help me?
Here is my code:
function cf7_dynamic_select() {
$choices = array(‘– Select a country –‘ => ”);
$query =array($wpdb->get_results(‘SELECT * FROM wp_custom_countries’));$choices = array_merge($choices, $query);
return $choices;
}
add_filter(‘my-filter’, ‘cf7_dynamic_select’, 10, 2);
wp_custom_countries has de following structure:
id iso nombre
1 AF Afganistán
2 AX Islas Gland
3 AL Albania
4 DE Alemania
5 AD Andorra
6 AO Angola
7 AI Anguilla
8 AQ Antártida
9 AG Antigua y Barbuda
10 AN Antillas HolandesasI would like to populate choices with the data
‘nombre1’ => ‘id1’, ‘nombre2’ => ‘id2’, …
Could you help me to do this? I have no good skill in php.
Thanks a lot.
- The topic ‘How to make a SQL query’ is closed to new replies.