Is there a limit to the number of "cases" in the Switch ( ) { case.. } ? i think i'm going to need 50/60 items thank you for your reply .
No, there is no limit, but if you have 50 items, there's a good chance that there's some other better way to structure your logic.
As long as you have switch ($_GET["mode"]) { case "new": ?> PHP: break; PHP: on your pages, you can have as many breaks; as you like and mode=new2 (example to enter the page) switch ($_GET["mode"]) { case "new2": ?> PHP:
Hi, Just thinking out loud here if its anything that needs that many switch statements it's going to be hard to test and debug... You could find alternate methods, arrays for example (page management) - $selPage = $_GET["page"]; $pages = Array ("index"=>"home.php", "about"=>"about.php"); foreach($pages as $key=>$val) { if($key == $selPage) { //$val contains the page value i.e. home.php //Include the page, or header() redirect it. } } PHP: Then if you add another page, just add another element to the array - A lot lesser code and more cleaner than a page full of if/switch statements. PS. Code wrote from memory, looks ok but needs testing Regards, Steve
interesting solution, but let's say i have a MySql table with 2 columns called "label" and "page" where i save the page name (label) and the page path (page) and i would create an array where the array's Key will have the "Label" column value and the array item's value will have the "Page" column value how could i obtain this ? thank you for your help .
It's not actually that much code, as we already have the setup for using an array to navigate the page - you just need to take the data from the database and put it in an array. <?php /* do all your mysql_connect() * stuff before anything else, * maybe even in an include file. */ $selPage = $_GET["page"]; $pages = Array(); $sqlQry = mysql_query("SELECT `page`, `label` FROM `pages`"); while($sqlResult = mysql_fetch_assoc($sqlQry)) { $pages[]["label"] = $sqlResult["label"]; $pages[]["page"] = $sqlResult["page"]; } ?> PHP: The above code will fill an array $pages with the following - Array ( [0] => Array ( [label] => Label 1 [page] => index.php ) [1] => Array ( [label] => Label 2 [page] => index1.php ) [2] => Array ( [label] => Label 2 [page] => index2.php ) [3] => Array ( [label] => Label 3 [page] => index3.php ) ) Code (markup): If you wanted to use the above array with the code I posted previously, it would need a slight change: foreach($pages as $key) { if($key["label"] == $selPage) { //Can either check the $key["label"] or $key["page"] //$val contains the page value i.e. home.php //Include the page, or header() redirect it. } } PHP: The above code now takes each entry of an array, as our new array is multidimensional we can use the array keys to do the checking. Regards, Steve