transform MySQL record into php variable and display in HTML?

1

I'm asking you to search the database for a result that matches a url variable I already have, it searches fine, but I want to get another column in the same row as the url it fetched type this:

| enrollment | name |

Search by enrollment, when you find it, take the corresponding name and put the result as the value of a variable. And show me in HTML. Please help me: (

This is an HTML page:

     <?php

        include ('conecta.php');

        $connection = mysqli_connect($host, $user, $pass,$database);
         if (!$connection) {
         echo ("Servidor temporariamente fora de servi?o"); 
        }

        $query = "SELECT * FROM resultado"
        . "WHERE nu_mat LIKE ".$url."";

        $result =  mysqli_query($connection,$query);
        if (!$result) {
          die("Query invalida na selecao dos dados");
        }

        while ($dados =  mysqli_fetch_array($result,MYSQLI_ASSOC)) {

           $dados = ['nm_aluno'];
        }


        ?>
<BODY>
<?php 
         echo"<p class='texto'>"; echo"$dados"; echo"</p>";
         ?>
</BODY>
    
asked by anonymous 07.04.2016 / 19:23

1 answer

3

The code $dados = ['nm_aluno']; may be invalid if you are using a version prior to php 5.4 and will not do what you are imagining.

An array is assigned to $dados with the value nm_aluno , remember that to access an array you must specify the variable ( $dados ) and the desired key ( nm_aluno ) with brackets.

This statement must be within the while to be executed N times

while ($dados =  mysqli_fetch_array($result,MYSQLI_ASSOC)) {
   echo "<p class='texto'>". $dados['nm_aluno'] ."</p>";
}

When you have questions about how to use an array, you can use the print_r() or var_dump() functions to cast it;)

    
07.04.2016 / 19:37