Message from mysql_fetch_array () expects parameter 1

2

I was trying to load content into an HTML table with the data I have in the database, but I find this "small" error. I have been visualizing different sites and as I did not find a quick and functional solution I come to you.

This is my PHP code.

<?php
session_start();
if(!isset($_SESSION["user"])){
header("location:login.php");
}
include "conexion.php";
$correo = $_SESSION["user"];
$query = "SELECT cbtahd.tblreportes.emisor,cbtahd.tblempleados.sucursal,cbtahd.tblreportes.area,cbtahd.tblempleados.extension,cbtahd.tblreportes.extension ,cbtahd.tblreportes.reporte, cbtahd.tblreportes.fechaEmi FROM tblempleados inner join tblreportes on tblreportes.receptor = tblempleados.nombreapellidoarea where tblempleados.email = '$correo'";
$resultado = mysql_query($query);

while ($fila = mysql_fetch_array($resultado, $conexion) or die (mysql_error())){
echo "fila[emisor]";
}
?>

This is the message that the server sends me

This is my connection.php file

<?php
$conexion = new mysqli("localhost","root","","cbtahd");
?>

And this is the select that I put in PHP running directly from the workbench.

    
asked by Guillermo Perez 25.07.2016 в 07:09
source

2 answers

2

In connection.php you are using mysqli and when making the query and get the results you use mysql_query and mysql_fetch_array . You have to adapt those functions to the extension mysqli

    
answered by 25.07.2016 в 10:05
2

The problem is that you are using different functions to make queries.

On the one hand you connect using the class mysqli and continue with the functions of mysql .

I'll give you three very simple examples of the functions mysql , mysqli and class mysqli .

MySql (Obsolete)

$conexion      = mysql_connect('localhost', 'usuario', 'contraseña');
$baseDeDatos   = mysql_select_db('base_de_datos', $conexion);
$consulta      = mysql_query('SELECT * FROM usuarios');
$salidaDeDatos = mysql_fetch_array($consulta);
mysql_close($conexion);

MySqli

$conexion      = mysqli_connect('localhost', 'usuario', 'contraseña', 'base_de_datos');
$consulta      = mysqli_query($conexion, 'SELECT * FROM usuarios');
$salidaDeDatos = $consulta->fetch_array();
mysqli_close($conexion);

MySqli Class

$conexion      = new mysqli('localhost', 'usuario', 'contraseña', 'base_de_datos');
$consulta      = $conexion->query('SELECT * FROM usuarios');
$salidaDeDatos = $consulta->fetch_array();
$conexion->close();

Depending on which you choose to work, you should keep the functions associated with each type of connection and avoid errors.

They vary a little the way of operating with each one. In the official PHP page you can find all the functions you need.

MySql and MySqli

    
answered by 25.07.2016 в 10:09