{"id":3972,"date":"2015-11-19T09:00:26","date_gmt":"2015-11-19T08:00:26","guid":{"rendered":"https:\/\/blogs.ua.es\/pi\/?p=3972"},"modified":"2015-12-26T10:25:37","modified_gmt":"2015-12-26T09:25:37","slug":"repetir-codigo-es-gratis","status":"publish","type":"post","link":"https:\/\/blogs.ua.es\/pi\/2015\/11\/19\/repetir-codigo-es-gratis\/","title":{"rendered":"Repetir c\u00f3digo es gratis"},"content":{"rendered":"<p>En una pr\u00e1ctica de mis alumnos, una p\u00e1gina PHP llamada \u00abdetalle foto\u00bb debe recibir un identificador de una fotograf\u00eda pasada por la URL (querystring) y debe mostrar los datos correspondientes.<\/p>\n<p>El c\u00f3digo de uno de mis alumnos es:<\/p>\n<pre>    if($v1==1){\r\n    include_once(RAIZ.'\/hiper\/perfil_joe.inc');\r\n    echo \"Identificador: $v1\";\r\n    }\r\n    else{\r\n        if($v1==2){\r\n        include_once(RAIZ.'\/hiper\/perfil_sandra.inc');\r\n        echo \"Identificador: $v1\";\r\n        }\r\n        else{\r\n            if($v1==3){\r\n            include_once(RAIZ.'\/hiper\/perfil_kevin.inc');\r\n            echo \"Identificador: $v1\";\r\n            }\r\n            else{\r\n                if($v1==4){\r\n                include_once(RAIZ.'\/hiper\/perfil_maria.inc');\r\n                echo \"Identificador: $v1\";\r\n                }\r\n                else{\r\n                    if($v1==5){\r\n                    include_once(RAIZ.'\/hiper\/perfil_demian.inc');\r\n                    echo \"Identificador: $v1\";\r\n                    }\r\n                    else{\r\n                        header('Location: index.php');\r\n                    }\r\n                }\r\n            }\r\n        }\r\n    }\r\n<\/pre>\n<p>No se le ocurri\u00f3 renombrar los nombres de los ficheros para que coincidiese con el identificador $v1. Tampoco se le ocurri\u00f3 crear un array y que el identificador fuese la posici\u00f3n en el array del nombre del fichero. No, simplemente se le ocurri\u00f3 encadenar un if detr\u00e1s de otro if. Pero si pens\u00f3 as\u00ed, \u00bfpor qu\u00e9 no utiliz\u00f3 el switch?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>En una pr\u00e1ctica de mis alumnos, una p\u00e1gina PHP llamada \u00abdetalle foto\u00bb debe recibir un identificador &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"more-link\" href=\"https:\/\/blogs.ua.es\/pi\/2015\/11\/19\/repetir-codigo-es-gratis\/\"> <span class=\"screen-reader-text\">Repetir c\u00f3digo es gratis<\/span> Read more \u2192<\/a><\/p>\n","protected":false},"author":40,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[6231],"class_list":["post-3972","post","type-post","status-publish","format-standard","hentry","category-general","tag-error"],"_links":{"self":[{"href":"https:\/\/blogs.ua.es\/pi\/wp-json\/wp\/v2\/posts\/3972","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.ua.es\/pi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.ua.es\/pi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.ua.es\/pi\/wp-json\/wp\/v2\/users\/40"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.ua.es\/pi\/wp-json\/wp\/v2\/comments?post=3972"}],"version-history":[{"count":1,"href":"https:\/\/blogs.ua.es\/pi\/wp-json\/wp\/v2\/posts\/3972\/revisions"}],"predecessor-version":[{"id":3973,"href":"https:\/\/blogs.ua.es\/pi\/wp-json\/wp\/v2\/posts\/3972\/revisions\/3973"}],"wp:attachment":[{"href":"https:\/\/blogs.ua.es\/pi\/wp-json\/wp\/v2\/media?parent=3972"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.ua.es\/pi\/wp-json\/wp\/v2\/categories?post=3972"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.ua.es\/pi\/wp-json\/wp\/v2\/tags?post=3972"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}