Drupal 7 Füllen Sie die Drop-Down wählen Sie aus der DB in Form API

Ich bin noch neu in PHP, und selbst neuere zu Drupal ' s Form API. Ich bin einfach versuchen, füllen Sie ein drop-down-select aus der Datenbank. Ich denke die Frage ergibt sich aus meinem Mangel an einem tiefen Verständnis davon, wie die Arbeit mit mehrdimensionalen arrays. Jede Hilfe ist herzlich willkommen.

Mein code ist aktuell:

    //Query DB for Rows
    $query = db_select('hp_education_years');
    $query->fields('hp_education_years', array('id', 'years',));
    $query->orderBy('years', 'ASC');
    $results = $query->execute();

    //define rows
    $options = array();
    foreach ($results as $result) {
        $options[$result->id] = array(
            $result->years,
        );
    }
    $form['education']['year'] = array(
        '#type' => 'select',
        '#title' => t('Year'),
        '#options' => $options,
        '#states' => array(
            'visible' => array(
                ':input[name="data_set"]' => array('value' => 'education'),
            ),
        ),
    );

Zurückgegebenen einem besiedelten Liste, sondern zeigt in der diesjährigen ID-Fett sowie das Jahr (2008 zum Beispiel).

Wie kann ich die dropdown nur zum anzeigen von Jahr, nicht das Jahr, in ID in Fett, und dann das Jahr. Wie es scheint, $option ist nur ein level höher als ich möchte es sein? ob das Sinn macht?

Vielen Dank im Voraus.

InformationsquelleAutor Lucas Healy | 2012-08-06
Schreibe einen Kommentar