dniwebdesign
05-08-2006, 07:15 AM
$result = mysql_query("SELECT * FROM sc_phpscart_category WHERE parent='0' ORDER BY category ASC");
$count=0;
if(mysql_num_rows($result))
{
echo "<strong>Sub-Category of: <select name='parent' style='background-color: transparent'>\n";
echo "<option value='".$returnID."' selected>".$info->getCatName($returnID)."</option>\n";
echo "<option value='0'>-- Top Level --</option>\n";
while($row=mysql_fetch_array($result))
{
$count=$count+1;
echo "<option value='".$row["id"]."'>".$row["category"]."</option>\n";
$result2 = mysql_query("SELECT * FROM sc_phpscart_category WHERE parent='".$row["id"]."' ORDER BY category ASC");
while($row2=mysql_fetch_array($result2))
{
//$count=$count+1;
echo "<option value='".$row2["id"]."'>| - ".$row2["category"]."</option>\n";
$result3 = mysql_query("SELECT * FROM sc_phpscart_category WHERE parent='".$row2["id"]."' ORDER BY category ASC");
while($row3=mysql_fetch_array($result3))
{
//$count=$count+1;
echo "<option value='".$row3["id"]."'> | - ".$row3["category"]."</option>\n";
}
}
}
echo '</select>';
}
else
{
echo '<div align="center"><font size="'.$font_size.'" face="'.$font_face.'">'.$error["nogigs"].'</font></div>';
}
Alright... to help with the last code I was doing I have this code which takes makes a drop list of categories and sub categories. However it is only limited to 3 sub categories and uses many mysql_queries. For example:
Motorcycles
| Harley-Davidson
| Parts
| Leathers
| T-Shirts
| Clothes
| Honda
| Parts
| Lights
| Yamaha
I would like to be able to make a list like that (dropdown) without using too many mysql_queries and that isn't limited to only 3 sub categories so I may have many sub-categories. How would I go about doing this more efficently than the way I am doing.
$count=0;
if(mysql_num_rows($result))
{
echo "<strong>Sub-Category of: <select name='parent' style='background-color: transparent'>\n";
echo "<option value='".$returnID."' selected>".$info->getCatName($returnID)."</option>\n";
echo "<option value='0'>-- Top Level --</option>\n";
while($row=mysql_fetch_array($result))
{
$count=$count+1;
echo "<option value='".$row["id"]."'>".$row["category"]."</option>\n";
$result2 = mysql_query("SELECT * FROM sc_phpscart_category WHERE parent='".$row["id"]."' ORDER BY category ASC");
while($row2=mysql_fetch_array($result2))
{
//$count=$count+1;
echo "<option value='".$row2["id"]."'>| - ".$row2["category"]."</option>\n";
$result3 = mysql_query("SELECT * FROM sc_phpscart_category WHERE parent='".$row2["id"]."' ORDER BY category ASC");
while($row3=mysql_fetch_array($result3))
{
//$count=$count+1;
echo "<option value='".$row3["id"]."'> | - ".$row3["category"]."</option>\n";
}
}
}
echo '</select>';
}
else
{
echo '<div align="center"><font size="'.$font_size.'" face="'.$font_face.'">'.$error["nogigs"].'</font></div>';
}
Alright... to help with the last code I was doing I have this code which takes makes a drop list of categories and sub categories. However it is only limited to 3 sub categories and uses many mysql_queries. For example:
Motorcycles
| Harley-Davidson
| Parts
| Leathers
| T-Shirts
| Clothes
| Honda
| Parts
| Lights
| Yamaha
I would like to be able to make a list like that (dropdown) without using too many mysql_queries and that isn't limited to only 3 sub categories so I may have many sub-categories. How would I go about doing this more efficently than the way I am doing.