php - Bootstrap - displaying categories from database vertically & alphabetically sorted in multiple rows -
i getting list of categories, varies page. 1 page may have 2, other may have 15 or 20.
right displaying them this:
<div class="row"> <div class="col-xs-4">airbags</div> <div class="col-xs-4">beanbags</div> <div class="col-xs-4">cats</div> <div class="col-xs-4">dogs</div> <div class="col-xs-4">eagles</div> <div class="col-xs-4">frogs</div> <div class="col-xs-4">hair clips</div> <div class="col-xs-4">jamaica</div> <div class="col-xs-4">microphones</div> </div>
it's bit hard read, though ...since displayed like:
airbags beanbags cats dogs eagles frogs hair clips jamaica microphones
what i'd display them vertically sorted
, it's like:
airbags dogs hair clips beanbags eagles jamaica cats frogs microphones
the way print data right this:
$output .= '<div class="row">'; array_multisort($names_array, sort_asc, $cat_array); foreach ((array) $cat_array $row) { $output .= '<div class="col-xs-3"> <a href="' . $row['subcat_link'] . '" class="">' . $row['name'] . '</a></div>'; } $output .= '</div>';
is there easy way i'm not aware achieve order want? if there 4 or more categories, think ...because otherwise impossible them underneath each other columns.
i using array_chunk
- split array 3 arrays, , show $i
th item each:
$cat_array = array_chunk((array)$cat_array, 3); foreach($cat_array $column) { $output .= '<div class="col-xs-3">'; foreach ($column $row) { $output .= '<div class="row"><div class="col-xs-12"><a href="' . $row['subcat_link'] . '" class="">' . $row['name'] . '</a></div></div>'; } $output .= '</div>'; }
Comments
Post a Comment