I got this error, times per row:
Notice: Undefined index: enviopre in /opt/lampp/htdocs/pruebax/pruebaxone.php on line 34
Notice: Undefined index: enviofra in /opt/lampp/htdocs/pruebax/pruebaxone.php on line 35
Notice: Undefined index: enviofec in /opt/lampp/htdocs/pruebax/pruebaxone.php on line 36
Notice: Undefined index: envioval in /opt/lampp/htdocs/pruebax/pruebaxone.php on line 37
.
.
.
Which means is returning all the values from the table but It can't be stored in the array. I tried changing the way each $row
receive the parameter, instead of the field name using the position in number of the array for example: $row[1]
$row[2]
$row[3]
... Still doesn't work...
this is my code:
<?php
class pruebax{
private static $cn = null;
public static function conectar(){
if (self::$cn !==null){
return self::$cnn;
}
try{
$cn = new PDO("informix:host=localhost; service=30000;database=mrroot; server=mrserver;protocol=onsoctcp;EnableScrollableCursors=1", "mrtony", "");
return $cn;
}catch (PDOException $ex){
die($ex->getMessege());
}
}
}
public static function consulta(){
$query = "SELECT * FROM fr_envio";
$cn = pruebaxone::conectar();
$resultado = $cnx->prepare($query);
$resultado->execute();
$rows = $query->fetch(PDO::FETCH_ASSOC);
echo '<table>';
foreach ($rows as $row){
echo '<tr>';
echo '<td>'.$row['enviopre'].'</td>';
echo '<td>'.$row['enviofra'].'</td>';
echo '<td>'.$row['enviofec'].'</td>';
echo '<td>'.$row['envioval'].'</td>';
echo '</tr>';
}
echo '</table>';
}
$prueba = new pruebaxone();
$prueba->consulta();
?>
Sorry if I made an obvious mistake, I'm learning...