Warning: Illegal string offset
Publicado por Victor (1 intervención) el 20/10/2019 23:02:16
Tengo un error al intentar consultar los datos que tenga una fecha, me arroja el siguiente error y no se muestra ningun campo... Warning: Illegal string offset, eso por cada campo en la base de datos... y no se donde esta mi error...
Modelo:
Controlador:
Vista:
La verdad no se donde esta el error, lo he buscado, pero no lo encuentro, se supone que valor del controlador, tomar el valor de la fecha que envio desde la vista, luego en el modelo se compara con lo que viene en item, que es el campo de fecha de entrega... pero no me funciona... soy novato pero con muchas ganas de aprender...
Modelo:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
static public function mdlExportarVentas($tabla1, $item, $valor){
if($item != null){
$stmt = Conexion::conectar()->prepare("SELECT * FROM $tabla1 WHERE $item = :$item");
$stmt -> bindParam(":".$item, $valor, PDO::PARAM_STR);
$stmt -> execute();
return $stmt -> fetch();
}else{
$stmt = Conexion::conectar()->prepare("SELECT * FROM $tabla1 ORDER BY fecha_entrega ASC");
$stmt -> execute();
return $stmt -> fetchAll();
}
$stmt -> close();
$stmt = null;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
static public function ctrExportarVentas(){
$tabla1 = "ventas";
if (isset($_POST['fechaExport'])) {
$valor = $_POST['fechaExport'];
$item = "fecha_entrega";
}else{
$item = null;
$valor = null;
}
$respuesta = ModeloVentas::mdlExportarVentas($tabla1, $item, $valor);
return $respuesta;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<section class="content" style="min-height: 100px !important;">
<div class="col-sm-4 col-sm-offset-4">
<form action="" class="form-signin" method="POST">
<div class="form-group">
<input type="text" class="form-control" name="fechaExport" id="exportarExcel" placeholder="Seleccione Fecha">
</div>
<input type="submit" class="btn btn-success btn-block" value="Consultar Fecha">
</form>
<?php
/*$Exportar = new ControladorVentas();
$exportar = ControladorVentas::ctrExportarVenta();*/
?>
</div>
</section>
<section>
<div class="content">
<h2>Previa</h2>
<div class="table-responsive">
<div class="top-panel">
<div class="btn-group pull-right">
<button type="button" class="btn btn-primary btn-lg dropdown-toggle dataExport" data-type="excel">Exportar</button>
</div>
</div>
<table id="dataTable" class="table table-bordered table-striped dt-responsive" style="font-size: 10px;">
<thead>
<tr>
<th>Fecha de Entrega</th>
<th>Vendedor</th>
<th>Cliente</th>
<th>Direccíon</th>
</tr>
</thead>
<tbody>
<?php
$export = ControladorVentas::ctrExportarVentas();
foreach ($export as $key => $value) {
echo '
<tr>
<td>'.str_replace('-', '/', date('d-m-Y', strtotime($value["fecha_entrega"]))).'</td>';
$itemUsuario = "id";
$valorUsuario = $value["id_vendedor"];
$respuestaUsuario = ControladorUsuarios::ctrMostrarUsuarios($itemUsuario, $valorUsuario);
echo '<td>'.$respuestaUsuario["nombre"].'</td>
<td>'.$value["cliente"].'</td>
<td>'.$value["direccion"].'</td>
</tr>
';
}
?>
</tbody>
</table>
Valora esta pregunta


0