Optimize the information page

Asked

Viewed 33 times

3

I have a page that receives monthly newsletters, to display the month desired by the user do the following:

<a href="?mes=ago2015" class="list-group-item 
<?=($mes=='ago2015')?'active':''?>" id="ago2015">Agosto / 2015</a>  

And call the referring page with a include:

$mes = empty($_GET['mes'])?'infos':$_GET['mes'];

case 'ago2015': 
    include('infos/agosto2015.php');
break;

Someone suggests some better way to do it?

  • For every month of every year you do it?

  • @Jorgeb. until a moment has 3 months, but in theory would be, so I want to change...

  • Bia the information of each month is in a database?

  • @Jorgeb. No, it’s pages.

  • 1

    So I’m not seeing a better way to do that. Let’s see if anyone has another idea.

  • 1

    I don’t see any other way to do this more optimally. If you were in a database it would be another story, but since you’re not, this is a good way to do it.

  • @Zoom I also like Flash, but changing the focus... These pages are made in HTML, in the right hand, if you did something more intent as a registration and put in the bank, would you solve this question? Because the more informative you insert, the bigger and "bad" this code would be.

  • 2

    That’s cool! The episode yesterday was top. So surely this information in a database would be better, for various reasons. It would have a better organization, maintenance, the code would not be extensive, they would not have many pages .html taking up space on your server. It takes a little bit of work to register everything, but it’s worth thinking about the usability of the system.

Show 3 more comments

1 answer

3


One way to optimize this, would be to create an array the keys are the months and the values the names of the files to do include. The ideal was to keep these values in the bank.

<?php
    $informativos = [
                    'set/2015' => 'info/set2015',
                    'out/2015' => 'info/out2015',
                    'nov/2015' => 'info/nov2015',
                    'dez/2015' => 'info/dez2015',
                    'padrao'   => 'info/404.php'    
    ];


    $mes = empty($_GET['mes']) ? 'padrao' : $_GET['mes'];

    include_once $informativos[$mes] .'.php';

Browser other questions tagged

You are not signed in. Login or sign up in order to post.