it-swarm.com.de

Füllen Sie das Dropdown-Menü aus der Joomla-Datenbank aus

Dies ist mein Code mit einem klassischen HTML-Dropdown mit großer Liste und einer Schaltfläche, die die Abfrage mit dem ausgewählten Wert ausführt:

<html>
<body>
<form name="lista" method="post" action="">
<select id="broj" name="name">                      
<option value="0">--Odaberi vrh--</option>
<option value="1">Maglić</option>
<option value="2">Vlasulja</option>
<option value="3">Veliki Oštrikovac</option>
...
<option value="73">Velika Lelija</option>
<option value="74">Bregoč</option>
<option value="75">Kozje strane</option>
<option value="76">Cincar</option>
</select>
<input type="submit" name="submit" value="SUBMIT" />
</form>
<?php
$peak = $_POST['name'];
    if ($_SERVER['REQUEST_METHOD'] == 'POST')
    {
----querry with $peak
}
?>

Dies ist eine Lösung von @jamesgarrett, bei der das Dropdown-Menü aus der Joomla-Datenbank ausgefüllt wird:

$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('peak_name');
$query->from($db->qn('#__peaks'));
$db->setQuery($query);
$peaks_list = $db->loadColumn();

// you could just echo out as you go if you prefer, but instead here we build up the html as a single string.
$peaks_select  = '<select name="name" id="peaks">';
$peaks_select .= '<option value="">-- Select Peak --</option>';

// here we use the peak_name for the value, whereas usually you set the value to the id of the table row. we're assuming there won't be any double quotes in these names.
foreach($peaks_list as $p){
    $peaks_select .= '<option value="' . $p . '">' . $p . '</option>';  
}
$peaks_select .= '</select>';

echo $peaks_select;

Aber es ist mir nie gelungen, den anderen Teil des Codes mit dem Button zu erstellen, der querry ausführt.

1
Midhat
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('peak_name');
$query->from($db->qn('#__peaks'));
$db->setQuery($query);
$peaks_list = $db->loadColumn();

// you could just echo out as you go if you prefer, but instead here we build up the html as a single string.
$peaks_select  = '<select name="name" id="peaks">';
$peaks_select .= '<option value="">-- Select Peak --</option>';

// here we use the peak_name for the value, whereas usually you set the value to the id of the table row. we're assuming there won't be any double quotes in these names.
foreach($peaks_list as $p){
    $peaks_select .= '<option value="' . $p . '">' . $p . '</option>';  
}
$peaks_select .= '</select>';


?><html>
<body>
<form name="lista" method="post" action="">
<?php echo $peaks_select; ?>
<input type="submit" name="submit" value="SUBMIT" />
</form>
<?php
$peak = $_POST['name'];
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
    // ----query with $peak
}
4
jamesgarrett