Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Code efficiency in menu
    primarykey
    data
    text
    <p>I currently have some VERY long winded code for the menu I use on my site. <a href="http://badnutbeats.co.uk/inotherwords" rel="nofollow">My website</a> It's almost 2000 lines long lol. I think I may be able to use a switch but I've tried and cannot implement it to work properly. </p> <p>On each menu when you click a button it stays highlighted, telling the user that they are on that page. The only way I could get this to work was like so...</p> <pre><code>if($subject == 'art') { echo '&lt;div id="spacer2"&gt;&lt;br&gt;&lt;/div&gt;'; echo '&lt;div class="idName2" id="menu2"&gt;'; echo '&lt;a href="browse.php?alphabet='.$alphabet.'&amp;subject=all&amp;listtype='.$listtype.'"&gt;All&lt;/a&gt;'; echo '&lt;div id="spacer2"&gt;&lt;br&gt;&lt;/div&gt;'; echo '&lt;/div&gt;'; echo '&lt;div class="idName3" id="menu3"&gt;'; echo '&lt;a href="browse.php?alphabet='.$alphabet.'&amp;subject=art&amp;listtype='.$listtype.'"&gt;Art&lt;/a&gt;'; echo '&lt;/div&gt;'; echo '&lt;div class="idName2" id="menu2"&gt;'; echo '&lt;a href="browse.php?alphabet='.$alphabet.'&amp;subject=biology&amp;listtype='.$listtype.'"&gt;Biology&lt;/a&gt;'; echo '&lt;a href="browse.php?alphabet='.$alphabet.'&amp;subject=english&amp;listtype='.$listtype.'"&gt;English&lt;/a&gt;'; echo '&lt;a href="browse.php?alphabet='.$alphabet.'&amp;subject=chemistry&amp;listtype='.$listtype.'"&gt;Chemistry&lt;/a&gt;'; echo '&lt;a href="browse.php?alphabet='.$alphabet.'&amp;subject=mathematics&amp;listtype='.$listtype.'"&gt;Mathematics&lt;/a&gt;'; echo '&lt;a href="browse.php?alphabet='.$alphabet.'&amp;subject=history&amp;listtype='.$listtype.'"&gt;History&lt;/a&gt;'; echo '&lt;a href="browse.php?alphabet='.$alphabet.'&amp;subject=religion&amp;listtype='.$listtype.'"&gt;Religion&lt;/a&gt;'; echo '&lt;a href="browse.php?alphabet='.$alphabet.'&amp;subject=geography&amp;listtype='.$listtype.'"&gt;Geography&lt;/a&gt;'; echo '&lt;a href="browse.php?alphabet='.$alphabet.'&amp;subject=music&amp;listtype='.$listtype.'"&gt;Music&lt;/a&gt;'; echo '&lt;a href="browse.php?alphabet='.$alphabet.'&amp;subject=philosophy&amp;listtype='.$listtype.'"&gt;Philosophy&lt;/a&gt;'; echo '&lt;a href="browse.php?alphabet='.$alphabet.'&amp;subject=psychology&amp;listtype='.$listtype.'"&gt;Psychology&lt;/a&gt;'; echo '&lt;a href="browse.php?alphabet='.$alphabet.'&amp;subject=economics&amp;listtype='.$listtype.'"&gt;Economics&lt;/a&gt;'; echo '&lt;a href="browse.php?alphabet='.$alphabet.'&amp;subject=sociology&amp;listtype='.$listtype.'"&gt;Sociology&lt;/a&gt;'; echo '&lt;a href="browse.php?alphabet='.$alphabet.'&amp;subject=technology&amp;listtype='.$listtype.'"&gt;Technology&lt;/a&gt;'; echo '&lt;a href="browse.php?alphabet='.$alphabet.'&amp;subject=electronics&amp;listtype='.$listtype.'"&gt;Electronics&lt;/a&gt;'; echo '&lt;a href="browse.php?alphabet='.$alphabet.'&amp;subject=food&amp;listtype='.$listtype.'"&gt;Food&lt;/a&gt;'; echo '&lt;a href="browse.php?alphabet='.$alphabet.'&amp;subject=law&amp;listtype='.$listtype.'"&gt;Law&lt;/a&gt;'; echo '&lt;a href="browse.php?alphabet='.$alphabet.'&amp;subject=politics&amp;listtype='.$listtype.'"&gt;Politics&lt;/a&gt;'; echo '&lt;/div&gt;'; } elseif($subject == 'biology') { </code></pre> <p>and then there's however many 'elseifs' as there are menu items, which ends up totalling to 2000 lines of code which is obviously very inefficient and it also makes it unbelievably time consuming to change anything... can someone point me in the right direction in what I need to do please!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload