How to cast a value before it is available?

0

I have a site in which I do a SQL that returns the records and the amount of records that I need to show on the site. For some reason that does not come the question, I no longer have the possibility to capture this variable before the header.

I have to put the data in parentheses that are at the top of the site.

Thisresultreturnstomevia%%ofSQLresultandtheamountofrecordsthatarealreadyinsertedbelowtheheader.HowdoIputthenumberofrecordsinthis"Results () ??

The code below shows well what I'm trying to do: grab $_POST['enviar'] and pull it up.

<?php

     echo $qteRegistros; <--------------------
     $qteRegistros = "380";

?>
    
asked by anonymous 10.10.2014 / 02:04

1 answer

4

Your problem seems to be that you are setting the variables in the wrong place like the example below - you want to use a variable that has not yet been defined.

<html>
    <head>
        <title><?php echo $total_registros; ?></title>
    </head>
    <body>
        <?php
        $PDO = DATABASE...
        $total_registros = $resultado_pdo;
        ?>
    </body>
</html>

The correct thing would be to separate the logic from the view , but I will not go into that merit. Just create the variables and use them later outside the HTML elements. So you can define all the variables and use them in HTML.

page.php

//Parte lógica do PHP
<?php
$PDO = DATABASE...
$total_registros = $resultado_pdo;
?>

//composição do HTML
<html>
    <head>
        <title><?php echo $total_registros; ?></title>
    </head>
    <body>
        Encontrados <?php echo $total_egistros; ?> registros.
    </body>
</html>

If I misunderstand your problem, give me more information.

    
10.10.2014 / 04:10