Jump to content

Dynamic menu, is there a more optimised way, too many selects


ORXXOR

Recommended Posts

I cant seem to optimise this code, im pretty new to php been developing for a year now, but this code seems so bloated to me, is there a better method to build this menu? There are so many selects to get the parent / child / seed menu levels to generate correctly. It's hurting my head so I signed up here to learn, please help........

 

<ul class="menu" id="menu">

<? // Set the main heading along the top of the menu

$a="SELECT * FROM `menu`"; $b=mysql_query($a); while ($c=mysql_fetch_array($b))

{

$parent=$c['parent'];

    if ($c['parent']!="" && $c['child']=="" && $c['seed']=="")

{?>

        <li><a href="#" class="menulink"><? echo $c['parent']; ?></a>

         

            <ul><? // Generate child menu, check if sub categories are available and provide sub menu if required

// Get the id and child names and build the child menu and links

$d="SELECT `id`, `child`, `seed` FROM `menu` WHERE `parent`= '$parent' && `seed`='' && `child`!=''"; $e=mysql_query($d);

while ($f=mysql_fetch_array($e)){ $child=$f['child']; $id=$f['id'];?>

               

                <li><a href="products.php?product=<? echo $id;?>&typ=child"

<? // Check to see if seed is full then add the arrow to link to sub menu (seed menu)

$g="SELECT * FROM `menu` WHERE `parent`='$parent' && `child`= '$child'"; $h=mysql_query($g); while ($j=mysql_fetch_array($h)){

if ($j['seed']!=""){?>class="sub"<? }}?>>

                <? if ($child!=""){echo $child;}?></a>

                    <ul>

                    <? // Grab the seed results and echo them looped if the seed value is not blank

  $k="SELECT * FROM `menu` WHERE `parent`='$parent' && `child`= '$child'"; $l=mysql_query($k); while ($m=mysql_fetch_array($l)){

if ($m['seed']!="")

{?>

                    <li><a href="products.php?product=<? echo $m['id'];?>&typ=seed"><? echo $m['seed'];?></a></li>

                    <? }}?>

                    </ul>

                </li>

                <? } ?>

            </ul>

        </li>

    <? }}?>

</ul>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.