when doing a sql query and traversing it gives me an error
function informe_stock_critico(){
$faltante=0;
$item="";
$total=0;
$subtotal=0;
$sql="SELECT count(CODIGO_PRODUCTO) AS subtotal,p.ID_CATEGORIA, NOMBRE_CATEGORIA from categorias c, producto p where c.ID_CATEGORIA=p.ID_CATEGORIA
and STOCK_REAL<=STOCK_MINIMO GROUP BY p.ID_CATEGORIA";
$resultado=mysqli_query($this->conexion,$sql);
while ($datos=mysqli_fetch_array($resultado)) {
$id=$datos["ID_CATEGORIA"];
$categoria=$datos["NOMBRE_CATEGORIA"];
$subtotal=$datos["subtotal"];
$sql2="SELECT CODIGO_PRODUCTO AS codigo,DESCRIPCION AS descripcion, STOCK_MAXIMO ,STOCK_MINIMO, p.RUT_PRO AS rut,pro.RAZON_SOCIAL As razon
FROM categorias c, producto p, proveedor pro
WHERE c.ID_CATEGORIA = p.ID_CATEGORIA
AND STOCK_REAL <= STOCK_MINIMO
AND pro.RUT_PRO = p.RUT_PRO
AND p.ID_CATEGORIA='$id'";
$resultado2=mysqli_query($this->conexion,$sql2);
// $fila=mysqli_num_rows($resultado2);
while ($datos2=mysqli_fetch_array($resultado2)) {
$codigo=$datos2=["codigo"];
$descripcion=$datos2["descripcion"];
$stock_max=$datos2["STOCK_MAXIMO"];
$stock_min=$datos2["STOCK_MINIMO"];
$rut=$datos2["rut"];
$nombre=$datos2["razon"];
$faltante=$stock_max-$stock_min;
$tabla.="<tr>
<td>$codigo</td>
<td>$descripcion</td>
<td>$faltante</td>
<td>$rut</td>
<td>$$nombre</td>
</tr>";
}
$fila=mysqli_num_rows($resultado2);
if ($fila>=1) {
$item.=$tabla."<tr><td colspan='3'>Total $categoria : $subtotal</td> </tr>";
}
$total=$total+$subtotal;
}
return $item."<tr><td colspan='3'>Total productos : $total</td> </tr>";
}
[! [enter the description of the image here] [3]] [3]