Buenas Tardes comunidad,
Desde hace mucho rato que tengo un problema con mi clase, es bien sencilla.
El principio de mi clase:
Código PHP:
public $production;
public function setProduction($x){
$this->production = $x;
}
public function getProduction(){
return $this->production;
}
Esta es la función en donde se debería de hacer la consulta y recolectar los registros de la base de datos.
Código PHP:
public function getProductionList()
{
if (isset($_SERVER['dbHost']) && ($_SERVER['dbUsr']) && ($_SERVER['dbPsw']) && ($_SERVER['db'])) {
$root = $_SERVER['DOCUMENT_ROOT'];
}else {
$root = $_SERVER['DOCUMENT_ROOT']."/";
}
include ($root."classes/connect.php");
// Create records array
$records = array();
// Execute query
if($results = $db->query("CALL wm.getProduction();")){
if($results->num_rows){
while($row = $results->fetch_object()){
$records[] = $row;
}
$results->free();
$this->setProduction($records);
}
}
$db->next_result(); // close query and prepare for next one.
} // End Function.
En esta función debería de recorrer todo el arreglo de la función anterior
Código PHP:
<?php
public function drawTable()
{
$records = $this->getProduction(); ?>
<table class="table table-striped table-hover">
<thead>
<tr>
<th>Production ID</th>
<th>Post Date</th>
<th>Vehicle ID</th>
<th>Weight</th>
<th>Cost Type</th>
<th>Total Cost</th>
</tr>
</thead>
<tbody> <?
if(!count($records)){ ?>
<tr valign="middle">
<td colspan="2" align="center"> <? echo 'No data available for this view'; ?> </td>
</tr><?pho
}else{
foreach($records as $r){?>
<tr>
<td><?php echo $r->production?></td>
<td><?php echo $r->post?></td>
<td><?php echo $r->vehicle?></td>
<td><?php echo $r->weight?></td>
<td><?php echo $r->cost?></td>
<td><?php echo $r->costTwo?></td>
</tr>
<?php } } ?>
</tbody>
</table>
<?php
}
?>
Entonces cuando la mando a llamar drawTable, en mi documento principal me sale el siguiente error:
Código:
Notice: Undefined variable: r in C:\xampp\htdocs\classes\employees.php on line 60
Comprobe que el procedimiento de la base de datos funcionará correctamente, que la tabla estuviera llena, comprobe todo. Lo que no entiendo es porque no me toma los valores
$R cuando en realidad la consulta si se realiza bien.
No se, si me explique bien, espero de su ayuda. De verdad se los agradeceré de corazón.