include with parameter?

2

Does include with parameter?

I have a page .php that contains the following code:

<ul class="nav nav-tabs">
  <li class="active"><a data-toggle="tab" href="#segunda">Segunda-Feira</a></li>
  <li><a data-toggle="tab" href="#terca">Ter&ccedil;a-Feira</a></li>
  <li><a data-toggle="tab" href="#quarta">Quarta-Feira</a></li>
  <li><a data-toggle="tab" href="quinta">Quinta-feira</a></li>
  <li><a data-toggle="tab" href="#sexta">Sexta-feira</a></li>
  <li><a data-toggle="tab" href="#sabado">S&aacute;bado</a></li>
</ul>

The nav nav-tabs class forms 6 tabs, and in each ABA, it displays the time of the string.

  • At ABA MONDAY I show the Monday times of FULANINHO
  • At ABA TUESDAY I show the times of Tuesday of the FULANINHO
  • And so on.

When I started to make the code I saw that it would be a repetition of everything, where it would only change the day of the week and the name of the FULANINHO that comes from the previous page via POST.

Then I thought of something like include('segunda.php',$id_fulaninho) . It is possible?

If not, would there be some way that I still do not know (I'm new to php ) of reducing this absurd amount of repeated     

asked by anonymous 08.08.2017 / 00:51

2 answers

3

There is no include with pars but, I could see in your question that this is easy, a example to illustrate:

Create the file that will be including in the other:

File name: _id.php

<?php

    echo $id;

Then create the file with this include :

File name: vid.php

<?php

    $id = 100;
    include('_id.php');

In this way the _id.php file has access to $id variable and its value can be used quietly, same and similar to what you intend in your tabs .

Remember that include can be used with the HTTP and passing arguments in the url:

<?php
    include('http://www.example.com/s.php?id=100');

But if the file is part of your project ( on the same file system ), it does not accept parameters.

References

08.08.2017 / 02:07
2

I suggest the following solution:

Create a function to receive the two parameters and return the desired html output.

Ex:

Function getHorarios.php

<?php

function getHorarios($dia_semana, $id_pessoa)
{
    $html_output = '';

    /*
    // .= concatena strings
    $html_output.= '10:00 - Alguma coisa. <br>';
    $html_output.= '12:00 - Outra  coisa. <br>';
    */

    return $html_output;
}

ajaxHorarios.php - Function call example:

<?php

    require('getHorarios.php');

    if( !empty($_POST["dia_semana"]) && !empty($_POST["id_pessoa"] )
    {
        $dia_semana = $_POST["dia_semana"];
        $id_pessoa  = $_POST["id_pessoa"];

        echo getHorarios($dia_semana, $id_pessoa);
    }
    else
    {
        echo 'Erro';
    }

For ajax calls: how to pass data to a function php by ajax url?

    
08.08.2017 / 03:51