Witam,
czy istnieje możliwość aby w wyświetlanej liście pojawiły się wartości z zapytania Mysql jak poniżej?
<http://december.com/html/4/element/select.html id="dino-select"> <http://december.com/html/4/element/optgroup.html label="Grupa 1"> <http://december.com/html/4/element/option.html>1</http://december.com/html/4/element/option.html> <http://december.com/html/4/element/option.html>2</http://december.com/html/4/element/option.html> <http://december.com/html/4/element/option.html>3</http://december.com/html/4/element/option.html> </http://december.com/html/4/element/optgroup.html> <http://december.com/html/4/element/optgroup.html label="Grupa 2"> <http://december.com/html/4/element/option.html>4</http://december.com/html/4/element/option.html> <http://december.com/html/4/element/option.html>5</http://december.com/html/4/element/option.html> <http://december.com/html/4/element/option.html>6</http://december.com/html/4/element/option.html> </http://december.com/html/4/element/optgroup.html> </http://december.com/html/4/element/select.html>
Tak, najpierw pogrupuj sobie dane:
http://nospor.pl/grupowanie-wynikow.html
a potem wyswietlaj jak chcesz
Dziękuję, prawie o to mi chodziło, mam teraz coś takiego:
$query = "SELECT id, NazwaDokumentu, Rejestr FROM Dokumentacja ORDER BY Rejestr ASC, NazwaDokumentu ASC"; $wynik0 = mysql_query($query); $categories = array(); while ($row = mysql_fetch_array($wynik0)){ $cid = $row['id']; IF (!isset($categories[$cid])) $categories[$cid] = array('name' => $row['Rejestr'], 'products' => array()); IF (!empty($row['NazwaDokumentu'])) //jeśli istnieje produkt $categories[$cid]['products'][] = array('name' => $row['NazwaDokumentu']); } echo ' <select class="form-control" name="Link0"> <option style="color:blue" value="">Wybierz dokument zapisany na serwerze</option>'; foreach ($categories AS $idCat => $category) { echo "<optgroup label=\"".$category[name]."\">"; foreach ($category['products'] AS $product) { echo '<option value="'.$id.'">'.$product['name'].'></option>'; } }
Kurcze. No ale miales moj przyklad dostosowac do swoich danych. Czy u ciebie ID jest odnosniekiem grupy? No nie. U mnie bylo, u cibeie nie jest. U ciebie wyznacznikiem grupy jest pole grupa
:-) Kurczę, oczywista oczywistość - dziękuję, o to mi chodziło
Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)