Problem with php code error array to string conversion and undefined index

0

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>";

}

gives me these errors

[! [enter the description of the image here] [3]] [3]

    
asked by jose miguel jara 27.11.2016 в 22:54
source

1 answer

1

The line $codigo=$datos2=["codigo"]; is overwriting the variable $datos2 that at the beginning of while contained the array with the fields in the query result record, but after that line, $datos2 only contains ["codigo"] .

I do not understand the purpose of that line, but starting with commenting, you should solve the aforementioned errors.

Then, see what was the original intention of that line and modify it.

    
answered by 28.11.2016 / 00:27
source