marcss
marcss

Reputation: 253

Not showing correct info PHP and Oracle query

My question is about an Oracle database which i can connect with PHP. With the same query using SQL Developer i've got this:

introducir la descripción de la imagen aquí

But in PHP:

$tsql= "select orden, fase, maquina_id, DescMaterial, dhsalida, scg_MaterialesLotes.lote, scg_MaterialesLotes.lotecli from scg_fases inner join scg_materiales on scg_fases.IdBoletin = scg_Materiales.IdBoletin inner join scg_MaterialesLotes on scg_Materiales.IdMatOf = scg_MaterialesLotes.IdMatOF";

$stmt = sqlsrv_query( $conn, $tsql);  

if ( $stmt )    
{ 
  ?>

  while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC))
  {
    $orden = $row["orden"];
    $fase = $row["fase"];
    $puesto = $row["maquina_id"];
    $art = $row["CodMaterial"];
    $desc = $row["DescMaterial"];
    $fecha = $row["dhsalida"];
    $lote = $row["scg_MaterialesLotes.lote"];
    $loteCli = $row["scg_MaterialesLotes.lotecli"];

    echo "<tr>";
    echo "<td align=center>" . $orden . "</td>";
    echo "<td align=center>" . $fase . "</td>";
    echo "<td align=center>" . $puesto . "</td>";
    echo "<td align=center>" . $art . "</td>";
    echo "<td align=center>" . $desc . "</td>";
    echo "<td align=center>" . $fecha . "</td>";
    echo "<td align=center>" . $lote . "</td>";
    echo "<td align=center>" . $loteCli . "</td>";
    echo "</tr>";
  }

  ?>
  </table>
  </body>
  </html>
  <?php
}     
else     
{    
  echo "Submission unsuccessful.";
  die( print_r( sqlsrv_errors(), true));    
} 

sqlsrv_free_stmt( $stmt);    
sqlsrv_close( $conn);

Using browser it shows:

introducir la descripción de la imagen aquí

Why i can't show the same info? Where is the problem? Thanks

Upvotes: 1

Views: 234

Answers (1)

AmmoPT
AmmoPT

Reputation: 958

1) Add CodMaterial field to your query You're not including the field CodMaterial in your query, so this line:

$art = $row["CodMaterial"];

Does nothing. So you can either add this field to the long list of fields in your query, or just use SELECT * FROM... to retrieve every field.

2) Don't use tablename.columnname in your query results rows When you query for scg_MaterialesLotes.lote for example, the resulting attribute will be called lote, so instead of having this in your PHP code:

$lote = $row["scg_MaterialesLotes.lote"];

Use this:

$lote = $row["lote"];

Do the same for scg_MaterialesLotes.lotecli

3) Echo $fecha as a string, at the moment is an object of type Instead of using:

echo "<td align=center>" . $fecha . "</td>";

Use this instead:

echo "<td align=center>" . ($fecha ? $fecha->format("Y-m-d H:i:s") : ""). "</td>";

Upvotes: 1

Related Questions