php - Selectbox Parent indent -
i have simlpe selectbox. it's printing out fine, want indent subcats layout looks like:
hardware - cpu - motherboards -- msi -- asus screens - dell -- 27" acer
in db table defined as:
id - label - parent
my current code is:
<select label="users" id="cat" onchange="showuser(this.value)" style="width:100%;padding:3px;cursor:pointer;"> <option value="">-- choose category -- </option> <?php $categories = $mysqli->query("select * medialib_cats"); while($row = $categories->fetch_assoc()){?> <option value="<?php echo $row['id']; ?>"> <?php echo $row['label']; ?> </option> <?php } ?> </select>
i have tried grouping results group by, did not work. how make automaticly indenting php/mysqli? guess should use recursion? indent lines -- , not using optgroup please :)
an option using optgroups:
<select label="users" id="cat" onchange="showuser(this.value)" style="width:100%;padding:3px;cursor:pointer;"> <option value="">-- choose category -- </option> <?php $categories = $mysqli->query("select * medialib_cats"); while($row = $categories->fetch_assoc()){ if ($lastgrp != $row['parent']) { if ($lastgrp!="") echo "</optgroup>"; $lastgrp = $row['parent']; echo "<optgroup>".$lastgrp; } echo "<option value="+ $row['id'] + ">"+ $row['label'] + "</option>"; } ?></optgroup> </select>
Comments
Post a Comment