I am trying to make a navigation rule for a website I am playing with. I have started adding a navigation rule for each city of Victoria (a state of Australia), but I only got 3 done, and I stopped and said: "There must be a quicker way of doing this". Can anyone help me to make this code shorter, and to include the cities that I have not yet added (which are commended out at the bottom)? <?php if ($state == "Victoria") { $nav_city = "Melbourne"; if ($city == "Melbourne") { $nav_melbourne = "nav_highlighted"; } else { $nav_melbourne = "nav_off"; } echo '<li class="'.$nav_melbourne.'" style="border-top: 1px solid #990000; border-bottom: 1px solid #990000;"><a href="/?state='.$state.'&city=melbourne">Melbourne</a></li>'; if ($city == "Ararat") { $nav_ararat = "nav_highlighted"; } else { $nav_ararat = "nav_off"; } echo '<li class="'.$nav_ararat.'"><a href="/?state='.$state.'&city=ararat">Ararat</a></li>'; if ($city == "Bairnsdale") { $nav_bairnsdale = "nav_highlighted"; } else { $nav_bairnsdale = "nav_off"; } echo '<li class="'.$nav_bairnsdale.'"><a href="/?state='.$state.'&city=bairnsdale">Bairnsdale</a></li>'; /* Benalla Ballarat Bendigo Dandenong Frankston Geelong Hamilton Horsham Melton Moe Morwell Mildura Sale Shepparton Swan Hill Traralgon Wangaratta Warrnambool Wodonga */ } ?> Code (markup):
Also, I could make a loop without asking for help - but I can't make a loop because each if else has a different city name added in the actual variable name. ie: if ($city == "Melbourne") { $nav_melbourne = "nav_highlighted"; } else { $nav_melbourne = "nav_off"; } Code (markup): Note: in the above, it could me nav_melbourne, or nav_ararat, or nav_bairnsdale or any one of the cities that are commented out. And I don't know how to make a variable - variable (if that makes sense).
You can do it by creating an array or loop. Loop will be needing database connection and you need to create table for it.
This topic is solved now. I got the answer here: http://www.simplemachines.org/community/index.php?topic=506789.new;topicseen#new