Error using include

Asked

Viewed 91 times

1

I have two php files that return one echo with a table. Work ok.

gestantCadastrada.php

echo '<h2>Gestantes Cadastradas</h2>';
echo '<table class="table table-striped">';
echo '<tr><th style="text-align:center;">Unidade</th><th style="text-align:center;">Gestante</th><th style="text-align:center;">Competência</th></tr>';

$total = 0;
$totalPrazo = 0;
while ($row = pg_fetch_assoc($result)) {
  if ($row['diferenca'] > 0){
    echo "<tr style='background-color:red; color:white'><td>".$row['nu_cnes']." - ".$row['unidade']."</td><td>".$row['nome']."</td><td>".str_pad($row['mes'], 2, "0", STR_PAD_LEFT)."/".$row['ano']."</td></tr>";
    $totalPrazo ++;
  }else{
    echo "<tr><td>".$row['nu_cnes']." - ".$row['unidade']."</td><td>".$row['nome']."</td><td>".str_pad($row['mes'], 2, "0", STR_PAD_LEFT)."/".$row['ano']."</td></tr>";
  }
  $total ++;
}

echo "<tr><td colspan='2'>TOTAL DE GESTANTES CADASTRADAS</td><td>".$total."</td></tr>";
echo "<tr><td colspan='2'>TOTAL DE GESTANTES CADASTRADAS INDEVIDAMENTE</td><td>".$totalPrazo."</td></tr>";
echo '</table>';

gestationAccompanied.php

echo '<h2>Gestantes Acompanhadas pelo ACS</h2>';
echo '<table class="table table-striped">';
echo '<tr><th style="text-align:center;">Unidade</th><th style="text-align:center;">Gestante</th><th style="text-align:center;">Competência</th></tr>';

$total = 0;
while ($row = pg_fetch_assoc($result)) {
  echo "<tr><td>".$row['nu_cnes']." - ".$row['no_equipe']."</td><td>".$row['no_cidadao']."</td><td>".$row['count']."</td></tr>";
  $total += $row['count'];
}

echo "<tr><td colspan='2'>TOTAL DE GESTANTES ACOMPANHADAS</td><td>".$total."</td></tr>";
echo '</table>';

And I have a file index.php who calls them both so:

include 'functions/gestanteCadastrada.php';
include 'functions/gestanteAcompanhada.php';

Everything works fine, however, what I want is for the gestationCadastrada.php file to call the gestationAcompanhada.php file this way:

include 'gestanteAcompanhada.php?gestanteCadastrada='.$total;
//veja que ele acrescenta uma variável à url

However I am getting file error not found:

Warning: include(pregnant.php?gestantCadastrada=8): failed to open stream: No such file or directory in C: wamp www relatorio functions gestanteCadastrada.php on line 57

And the file is in the right place. What can be?

1 answer

1


From what I understand, you can’t give a include by passing parameters. When you give a include it looks for a file on the server and does not run it as if it were on the web. That’s why you won’t find a file called "gestantAcompanhada.php? gestanteCadastrada=8".

Edit: You can solve your case with Sessions, or even calling the file as a service.

  • 1

    What a pity. Any suggestions on how to get around this?

  • Well, in the example you gave above, I think if you just insert the file, without parameters, it would work because anyway, you’re not using this information on the page right? In fact, you’re zeroing in on the total variable... But if you use the parameter, you can use a session, where the page to be included reads the session and takes the value, or you can call only this page as a web request, a Gambi for service understands?

  • 1

    I managed to solve using Sessions. Thanks. You can change your answer and I’ll give you points

  • Thanks mann. Hugs.

Browser other questions tagged

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