Quantcast
Channel: Topic Tag: database | WordPress.org
Viewing all articles
Browse latest Browse all 11065

xnau on "[Plugin: Participants Database] Dropdown values from specific field"

$
0
0

Sure, OK. You don't explain if the people who offer the help will type in the name of their activity, or if they choose it from a list. If you let them type it in, you may end up with several slightly different activities that are actually the same activity...this could be confusing to your second group of users. I mention this so you can think about how that might work.

The solution is the same either way.

You can use code something like this to produce your dropdown:

<?php
global $wpdb;
$field = 'activity_title';
$activities = array();
// grab the unique stored values from the field
$result = $wpdb->get_results('SELECT DISTINCT p.' . $field . ' from ' . Participants_Db::$participants_table . ' p WHERE p.' . $field . ' <> ""', ARRAY_N);
// now we convert the query result into a simple array
foreach($result as $value) {
  $activities[] = current($value);
}
// print the dropdown
echo PDb_FormElement::get_element(array(
    'name' => 'selected_activity',
    'type' => 'dropdown',
    'options' => $activities
        )
    );
?>

The database query gets all unique values stored in the 'activity_title' field, then makes a dropdown selector with the values.


Viewing all articles
Browse latest Browse all 11065

Trending Articles