HTML and SQL connection [closed]

1

I'm designing a database with where I have a table with calculated indexes of data from other tables. I'm also designing an HTML dashboard to expose these indexes. My database is stored on a MySQL server. How do I extract this data and expose it on the dashboard by linking the two technologies?

    
asked by anonymous 31.07.2017 / 04:20

2 answers

5

Mysql .

PHP

Using PHP you should create a .php file and set its connection to the database.

Ex:

<?php
define("HOST", "nomedohost");    #Para o host com o qual você quer se conectar.
define("USER", "nomedousuario");          #O nome de usuário para o banco de dados. 
define("PASSWORD", "senha");           #A senha do banco de dados. 
define("DATABASE", "bancodedados");       #O nome do banco de dados. 
$mysqli = new mysqli(HOST, USER, PASSWORD, DATABASE);
?>

And then call it when you need to connect to the database.

To use a PHP file, the file you are going to call must be .php Ex: index.php

And in it you must make the request of your .php file with the database, let's imagine that the file you created is called db.php .

As I see you already know SQL , I'll give you an example using Mysql .

Let's imagine your table looks like this:

Nome da tabela: users
Colunas: username, profile
username: Foo
profile: é um cara legal.

PHP file with your HTML

<?php
    require_once('db.php');
    $username = "Foo";
    $sql = "SELECT * FROM 'users' WHERE 'username' = '$username'"; #sua query sql, um exemplo o SELECT *
    $query_exec = $mysqli->query($sql); #Executa o comando select.
    $row = $query_exec->num_rows; #Número de resultados encontrados.
    $get = $query_exec->fetch_array(); #Cria um vetor associativo com os dados.
    if($row > 0) {
        #encontrou resultados.
        $usuario = $get['username']; 
        $perfil = $get['profile'];
        echo "{$usuario} {$perfil}"; #Pode fazer um echo de um html, ex: echo '<div id="profile">'.$perfil.'</div>';
        #O resultado do echo seria: Foo é um cara legal.

    } else {
        #não encontrou nada.    
    }

?>
<!DOCTYPE html>
<html>
    <head>

    </head>
    <body>
    <!--Colocando as tags PHP para exibir o echo no HTML-->
    <div id="username"> <?php echo $usuario; ?> </div>
    </body>
</html>

There are a lot of ways you can manipulate PHP , you can do it using AJAX , AJAX + Json being very extensive, but as you need to learn to use the database, you can start by doing some PHP course, and if you are not knowledgeable in programming, take a course in programming logic.

    
31.07.2017 / 06:11
5

You will not be able to make this connection with html. To do this you will need a programming language that supports this connection.

    
31.07.2017 / 04:33