[SOLVED] Grouping for select box
Posted: Wed Oct 06, 2004 3:06 pm
I need to group a selection of items from database- there are two fields
1, type
2, newbuild
i need to group all types and also which are newbuild, I have the following code but it displays the following:
heres the display

can anybody spot why it is showing 2 newbuilds in the input box ?
Cheers
1, type
2, newbuild
i need to group all types and also which are newbuild, I have the following code but it displays the following:
heres the display

Code: Select all
function gettypes($table)
{
$query = "SELECT type, newbuild, COUNT(*) as items FROM `".$table."` WHERE status != 'hide' group by type, newbuild order by items DESC, type;";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
if ($num_results > 7)
$selectSize = 7;
else
$selectSize = $num_results + 1;
echo '<select class="inputbox" name="type[]" MULTIPLE size='.$selectSize.'>';
echo '<option value="any" selected > - any -</option>';
for ($i= 0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
if ($row["newbuild"] <>"newbuild") {
echo stripslashes('<option value="'.$row["type"].'">'.$row["type"].' ('.$row["items"].')'.'</option>');
}else {
echo stripslashes('<option value="'.$row["newbuild"].'">'.$row["newbuild"].' ('.$row["items"].')'.'</option>');
} }
echo '</select>';
}Cheers