php - running a mysql count command within a looped drop down function -
basically, have created drop down box populated mysql database of primary catagories. when selection made, ajax function called runs query display sub catagories.
for example,
primary_catagory = p
sub_catagory = s
p s
1 a
1 b
1 c
2 d
2 e
2 f
so when selection made in primary category, show either a,b , c or d, e , f depending on if 1 or 2 selected. query works fine except final cosmetic feature, show number of sub categories contained within primary one.
so drop down box show choice (3) , choice b (2) example.
this code have far, displays (1) every result. code stands.
<select id="p_catagory" name="p_catagory" onchange = "getdata(this); return true;" style="position:absolute;left:0px;top:10px;width:315px;height:20px;z-index:11;text-align:left;"> if ($_get['p_catagory'] == "all") { <option value='all'>show all</option> } while ($row = mysqli_fetch_array($result, mysql_assoc)) { $query2 = "select * db_class_catagories primary_catagory=".$var; $result2 = mysqli_query($dbconnection, $query2); $entries = count($result2); echo "<option value='" . $row['primary_catagory'] . "'>" . $row['primary_catagory'] . " " . "(" . $entries . ")" . "</option>"; } ?> </select>
ive been on days , cant seem find work around, suggestions?
thanks
please try use:
$entries = mysqli_num_rows($result2);
instead of old line:
$entries = count($result2);
i think should help.
Comments
Post a Comment