The next time you use the mysqli or PDO libraries to work with your databases, since mysql is currently not used much, but when you are working on accessing a specific field of the table and putting it into a div , or something dynamically, I do it with PDO, and I leave you my way of doing it
try
{
$bbdd_conection = new PDO("mysql:host=localhost;dbname=mi_tabla", "root", "");
if
($bbdd_conection->errorCode())
{
die("Fallo al conectar con la base de datos");
}else {
$bbdd_conection->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$bbdd_conection->exec('SET CHARACTER SET UTF8');
$stm = "SELECT * nombre_tabla"
$objeto = $bbdd_conection->prepare($stm);
$objeto->execute();
$resultado_demi_tabla = $objeto->fetchAll(PDO::FETCH_OBJ);
foreach($resultado_demi_tabla as $valor){
print_r($valor) // usarlo para testear
echo $valor->campo1
//Con esto podras acceder a cada campo que devuelve el registro de tu tabla, si tu tabla se llama nombre,edad etc con $valor->edad podras ver los resultados y utilizarlos.
}
//
}
} catch (PDOException $ex) {
echo "Fallo al conectar o enviar una consulta a la base de datos en la linea " . $ex->getLine()
. " y el causante del fallo es " . $ex->getMessage() . PHP_EOL;
}finally{
$bbdd_conection = NULL;
}
}
}
>