How do I make a database search appear in a table?

0

A few days ago I'm trying to make my DB search look inward to a bordered table. However, although the server does not return any errors, no results are shown. I have already made several changes in the syntax regarding the positioning of the tags tables, placing it internally in the WHILE but until now I did not get any success. Here is the last way I tried:

<html>

<head>
    <title>Extraindo dados do BD</title>
</head>
<body>
    <?php
        mysql_connect("localhost","DB1","XXXX") or die(mysql_error());
        mysql_select_db("database1") or die(mysql_error());
        $selecaodedados= "SELECT * FROM meubancodedados";
        echo "<table style="1px">";
            echo    "<thead>    <tr> <th colspan='6'>Lista 1 </th></tr>"    
                ."</tread>";
            echo    "<tr>"
                ."<th> A dado </th> <th> B dado </th> <th> C dado </th>"
                ." <th>D dado </th> <th> E dado </th> <th> F total </th>"
                ."</tr>";
            echo    "</thead>";
            echo    " <tbody>";
        while($linha= mysql_fetch_array($selecaodedados)){
            echo "<tr>"
                ."<td>".$linha['A']. "</td><td> ". $linha['B']"
                . " </td><td> ".$linha['C']. "</td><td>  ". $linha['D']"
                . "</td><td>  ". $linha['E']."</td><td>  ".$linha['F']. "</td><br/>"
                ."</tr>";
            }
            echo "</tbody>";
            echo "</table>";            
        mysql_close();
    ?>
</body>

    
asked by anonymous 26.12.2016 / 22:14

2 answers

0

Hello. Since now I do not recommend using MySql, since it is obsolete and is discontinued. And it was also removed in version 7.0.0 of PHP.

But as the question was asked about MySQL, let's answer it! In your code you were missing a query

The correct one would be:

<html>

<head>
    <title>Extraindo dados do BD</title>
</head>
<body>
    <?php
        mysql_connect("localhost","USUARIO","SENHA") or die(mysql_error());
        mysql_select_db("DATABASE") or die(mysql_error());
        $selecaodedados= "SELECT * FROM TABELA";
        $executar = mysql_query("$selecaodedados");
        echo "<table style='1px'>";
        echo    "<thead>    <tr> <th colspan='6'>Lista 1 </th></tr>";    
        echo "</tread>";
        echo   "<tr>";
        echo "<th> A dado </th> <th> B dado </th> <th> C dado </th>";
        echo " <th>D dado </th> <th> E dado </th> <th> F total </th>";
        echo "</tr>";
        echo  "</thead>";
        echo   " <tbody>";
    while($linha= mysql_fetch_array($executar)){
        echo "<tr>";
        echo "<td>".$linha['A']."</td><td>" .$linha['B'];
        echo  "</td><td>".$linha['C']."</td><td> ".$linha['D'];
        echo "</td><td>  ".$linha['E']."</td><td> ".$linha['F']."</td><br/>";
        echo "</tr>";
        }
        echo "</tbody>";
        echo "</table>";            
    mysql_close();
?>

In addition, your code was missing many ";" As you can see, the changes were:

  

$ run = mysql_query ("$ selectedseasons");

     

while ($ row = mysql_fetch_array ($ execute)) {

    
26.12.2016 / 22:37
0

To facilitate you can put a for in while :

<table>
<?php
    while($linha= mysql_fetch_row($selecaodedados)){
        echo "<tr>";
        for($x=0; $x<count($linha); $x++)
            echo "<td>".$linha[$x]."</td>";
        echo "</tr>";
    }
?>
</table>

Using mysql_fetch_assoc you will have a numeric vector for the information, so it will be easier to traverse as a vector.

    
26.12.2016 / 22:28