Pregunta:
Fecha: 15-01-2016 06:13:14
(En Español)
les adjunto las capturas:
Img 01
img 02
Los archivos :
EstacionData.php
Archivo de estacion.php
Por favor haber si me pueden ayudar a ver cual es el problema, Gracias Votos: 3 - Respuestas: 2 - Vistas: 16 Compartir en: Google Facebook Twitter LinkedIn Link
Problemas a compaginar en PHP, y Bootstrap[Resuelta]
Hola, primeramente tengan un saludo cordial para todos, bueno tengo un problemas al momento de generar mi listado por categoría.les adjunto las capturas:
Img 01
img 02
Los archivos :
EstacionData.php
<?php
class EstacionData {
public static $tablename = "estacion";
public function EstacionData(){
$this->codigo = "";
$this->terminal = "";
$this->ip_privado = "";
$this->ip_publica = "";
$this->mac = "";
$this->motivo = "";
$this->created_at = "NOW()";
}
public function getCategoria(){ return CategoryData::getById($this->categoria_id); }
public function getPlan(){ return PlanData::getById($this->plan_id); }
public function add(){
$sql = "insert into ".self::$tablename."(codigo, terminal, plan_id, ip_privado, ip_publica, mac, categoria_id, motivo, created_at) ";
$sql .= "value (\"$this->codigo\", \"$this->terminal\", $this->plan_id,\"$this->ip_privado\", \"$this->ip_publica\", \"$this->mac\",$this->categoria_id, \"$this->motivo\", $this->created_at)";
Executor::doit($sql);
}
public static function delById($id){
$sql = "delete from ".self::$tablename." where id=$id";
Executor::doit($sql);
}
public function del(){
$sql = "delete from ".self::$tablename." where id=$this->id";
Executor::doit($sql);
}
// partiendo de que ya tenemos creado un objecto EstacionData previamente utilizamos el contexto
public function update(){
$sql = "update ".self::$tablename." set codigo=\"$this->codigo\",terminal=\"$this->terminal\",plan_id=\"$this->plan_id\",ip_privado=\"$this->ip_privado\",ip_publica=\"$this->ip_publica\", mac=\"$this->mac\" ,categoria_id=\"$this->categoria_id\", motivo=\"$this->motivo\" where id=$this->id";
Executor::doit($sql);
}
public static function getById($id){
$sql = "select * from ".self::$tablename." where id=$id";
$query = Executor::doit($sql);
return Model::one($query[0],new EstacionData());
}
public static function getAll(){
$sql = "select * from ".self::$tablename." WHERE categoria_id=1 order by id desc";
$query = Executor::doit($sql);
return Model::many($query[0],new EstacionData());
}
public static function getAll2(){
$sql = "select * from ".self::$tablename." WHERE categoria_id=2 order by id desc";
$query = Executor::doit($sql);
return Model::many($query[0],new EstacionData());
}
public static function getAll3(){
$sql = "select * from ".self::$tablename." WHERE categoria_id=3 order by id desc";
$query = Executor::doit($sql);
return Model::many($query[0],new EstacionData());
}
public static function getAll4(){
$sql = "select * from ".self::$tablename." WHERE categoria_id=4 order by id desc";
$query = Executor::doit($sql);
return Model::many($query[0],new EstacionData());
}
public static function getAllByPage($start_from,$limit){
$sql = "select * from ".self::$tablename." where id>=$start_from limit $limit";
$query = Executor::doit($sql);
return Model::many($query[0],new EstacionData());
}
public static function getLike($q){
$sql = "select * from ".self::$tablename." where terminal like '%$q%' or email like '%$q%'";
$query = Executor::doit($sql);
return Model::many($query[0],new EstacionData());
}
}
?>
Archivo de estacion.php
<div class="row">
<div class="col-md-12">
<h1>Lista de Estaciones Activas</h1>
<div class="clearfix"></div>
<?php
$page = 1;
if(isset($_GET["page"])){
$page=$_GET["page"];
}
$limit=10;
if(isset($_GET["limit"]) && $_GET["limit"]!="" && $_GET["limit"]!=$limit){
$limit=$_GET["limit"];
}
$users = EstacionData::getAll();
if(count($users)>0){
if($page==1){
$curr_users = EstacionData::getAllByPage($users[0]->id,$limit);
}else{
$curr_users = EstacionData::getAllByPage($users[($page-1)*$limit]->id,$limit);
}
$npaginas = floor(count($users)/$limit);
$spaginas = count($users)%$limit;
if($spaginas>0){ $npaginas++;}
?>
<h3>Pagina <?php echo $page." de ".$npaginas; ?></h3>
<div class="btn-group pull-right">
<?php
$px=$page-1;
if($px>0):
?>
<a class="btn btn-sm btn-default" href="<?php echo "index.php?view=estaciones&limit=$limit&page=".($px); ?>"><i class="glyphicon glyphicon-chevron-left"></i> Atras </a>
<?php endif; ?>
<?php
$px=$page+1;
if($px<=$npaginas):
?>
<a class="btn btn-sm btn-default" href="<?php echo "index.php?view=estaciones&limit=$limit&page=".($px); ?>">Adelante <i class="glyphicon glyphicon-chevron-right"></i></a>
<?php endif; ?>
</div>
<div class="clearfix"></div>
<br><table width="685" class="table table-bordered table-hover">
<thead>
<th>Nombre completo</th>
<th>Plan</th>
<th>Mac</th>
<th>IP Privada</th>
<th>IP Publica</th>
<th>Motivo</th>
<th>Estado</th>
<th>Acciones</th>
<?php foreach($curr_users as $user):
$categoria = $user->getCategoria();
$plan = $user->getPlan();
?>
<tr>
<td><?php echo $user->codigo." - ".$user->terminal; ?></td>
<td><?php echo $plan->nombre." "; ?></td>
<td><?php echo $user->mac; ?></td>
<td><?php echo $user->ip_privado; ?></td>
<td><?php echo $user->ip_publica; ?></td>
<td><?php echo $user->motivo; ?></td>
<td><?php echo $categoria->nombre." "; ?></td>
<td style="width:180px;">
<a href="index.php?view=averiashistory&id=<?php echo $user->id;?>" class="btn btn-xs btn-success">Averias</a>
<a href="index.php?view=editestacion&id=<?php echo $user->id;?>" class="btn btn-warning btn-xs">Editar</a>
<a href="index.php?view=delestacion&id=<?php echo $user->id;?>" class="btn btn-danger btn-xs">Eliminar</a>
</td>
</tr>
<?php endforeach;?>
</table>
<div class="btn-group pull-right">
<?php
for($i=0;$i<$npaginas;$i++){
echo "<a href='index.php?view=estaciones&limit=$limit&page=".($i+1)."' class='btn btn-default btn-sm'>".($i+1)."</a> ";
}
?>
</div>
<form class="form-inline">
<label for="limit">Limite</label>
<input type="hidden" name="view" value="estaciones">
<input type="number" value=<?php echo $limit?> name="limit" style="width:60px;" class="form-control">
</form>
<div class="clearfix"></div>
<?php
}else{
?>
<div class="jumbotron">
<h2>No Estaciones Activas</h2>
</div>
<?php
}
?>
</div>
</div>
Por favor haber si me pueden ayudar a ver cual es el problema, Gracias Votos: 3 - Respuestas: 2 - Vistas: 16 Compartir en: Google Facebook Twitter LinkedIn Link
Respuestas:
-
Fecha: 15-01-2016 06:52:02 Acabo de ver tu codigo y analizar las lineas creo q el error esta aqui en la linea 20
$curr_users = EstacionData::getAllByPage($users[0]->id,$limit);
cambia por esto
$curr_users = EstacionData::getAllByPage(0,$limit);
haz el cambio y prueba
por otro lado veo esto
public static function getAllByPage($start_from,$limit){ $sql = "select * from ".self::$tablename." where id>=$start_from limit $limit"; $query = Executor::doit($sql); return Model::many($query[0],new EstacionData()); }
veo que muestras lo registros q sea mayores al valor q envia es por eso que quizas al principio solo el registro q se visualiza cumple con la condicion.
cambia por esto
public static function getAllByPage($start_from,$limit){ $sql = "select * from ".self::$tablename." order by id asc limit $start_from,$limit"; $query = Executor::doit($sql); return Model::many($query[0],new EstacionData()); }
saludos , espero haberte ayudado Votos: 5 - Link respuesta -
Fecha: 15-01-2016 11:16:07 Gracias por tu cooperación fue de mucha ayuda, gracias. Votos: 2 - Link respuesta
Para participar activamente de la comunidad primero debes autenticarte, ingresa al sistema.Iniciar Sesión
