erro em paginação no PHP
24/08/2017
0
Segue meu código.
<?php @header( 'Content-Type: text/html; charset=iso-8859-1' ); require_once 'database/mysql.php'; $db = new Mysql; ?> <!DOCTYPE html> <html> <head> <title>News</title> <link href="css/home.css" rel="stylesheet"> <link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet"> <script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script> </head> <body> <div id="news" class="span12"> <?php //$db->url = 'noticias.php'; $db->paginate(4); $db->query("select * from noticias2 order by idnoticia desc")->fetchAll(); if ($db->rows >= 1): $news = $db->data; foreach ($news as $new): $n = (object) $new; $n->noticia_content_cut = $db->cut($n->notlead, 300, '...'); if ($n->notimg == "" || strlen($n->notimg) <= 1): $n->notimg = "images/nopic.png"; else : $n->notimg = "thumb.php?img=fotos/$n->notimg"; endif; ?> <div class="media"> <a class="pull-left" href="noticia.php?id=<?php=$n->idnoticia?>"> <img src="<?php=$n->notimg?>" class="media-object img-polaroid" /> </a> <div class="media-body"> <h4 class="media-heading"><?php=$n->idnoticia?></h4> <p><small><?php=$n->noticia_content_cut ?> <em><a href="noticia.php?id=<?php= $n->idnoticia ?>" class="btn btn-link">leia mais</a></em></small> </div> </div> <hr /> <?php endforeach; echo $db->link ; endif; ?> </div> </body> </html>
Claudemir
Posts
25/08/2017
Fabio Rocha
Tente imprimir com var_dump os seguintes itens e cole aqui para que possa dar uma olhada melhor
<?php var_dump($db->rows); ?>
<?php var_dump($db->data); ?>
Abraços.
25/08/2017
Claudemir
'idnoticia' => string '19' (length=2) 'notcat' => string '1' (length=1) 'notedi' => string '16' (length=2) 'notdata' => string '2016-09-13' (length=10) 'notitulo' => string 'LITURGIA XII - TEMPO COMUM - ANO C - 18º AO 34º DOMINGO' (length=55) 'notlead' => string 'liturgia xii ' (length=14) 'notcorpo' => string 'comum xii' (length=9) 'notfonte' => string '' (length=0) 'notautor' => string 'CNBB' (length=4) 'notimg' => string '9c50a5334ba74841724f7bf66fcbe982.jpg' (length=36) 'ativa' => string '1' (length=1) 'destaque' => string '2' (length=1) 'datacad' => string '2016-09-13 18:17:08' (length=19) 'dataalt' => string '2016-09-13 18:19:22' (length=19) 'idoperador' => string '0' (length=1) 'controle' => string '1' (length=1) 1 => array (size=16) 'idnoticia' => string '18' (length=2) 'notcat' => string '1' (length=1) 'notedi' => string '16' (length=2) 'notdata' => string '2016-05-20' (length=10) 'notitulo' => string 'LITURGIA XI - TEMPO COMUM - ANO C - 2º AO 17º DOMINGO' (length=53) 'notlead' => string 'liturgia xi' (length=11) 'notcorpo' => string 'comum xi' (length=8) 'notfonte' => string '' (length=0) 'notautor' => string 'CNBB' (length=4) 'notimg' => string '9c50a5334ba74841724f7bf66fcbe982.jpg' (length=36) 'ativa' => string '1' (length=1) 'destaque' => string '2' (length=1) 'datacad' => string '2016-05-20 19:16:51' (length=19) 'dataalt' => string '2016-09-11 16:57:50' (length=19) 'idoperador' => string '0' (length=1) 'controle' => string '1' (length=1) 2 => array (size=16) 'idnoticia' => string '17' (length=2) 'notcat' => string '7' (length=1) 'notedi' => string '16' (length=2) 'notdata' => string '2016-03-30' (length=10) 'notitulo' => string 'MúSICAS CIFRADAS DO HINáRIO LITúRGICO DA CNBB - LITURGIA XV - ANO C - TEMPO PASCAL' (length=82) 'notlead' => string 'liturgia xv' (length=11) 'notcorpo' => string 'comum xv' (length=8) 'notfonte' => string '' (length=0) 'notautor' => string 'CNBB' (length=4) 'notimg' => string '9c50a5334ba74841724f7bf66fcbe982.jpg' (length=36) 'ativa' => string '1' (length=1) 'destaque' => string '2' (length=1) 'datacad' => string '2016-03-30 18:26:25' (length=19) 'dataalt' => string '2017-04-21 15:34:01' (length=19) 'idoperador' => string '0' (length=1) 'controle' => string '1' (length=1) 3 => array (size=16) 'idnoticia' => string '16' (length=2) 'notcat' => string '6' (length=1) 'notedi' => string '16' (length=2) 'notdata' => string '2016-03-12' (length=10) 'notitulo' => string 'MúSICAS CIFRADAS DO DOMINGO DE RAMOS' (length=36) 'notlead' => string 'ramos' (length=5) 'notcorpo' => string 'ramos ii' (length=8) 'notfonte' => string '' (length=0) 'notautor' => string 'CNBB' (length=4) 'notimg' => string '9c50a5334ba74841724f7bf66fcbe982.jpg' (length=36) 'ativa' => string '1' (length=1) 'destaque' => string '2' (length=1) 'datacad' => string '2016-03-12 07:52:24' (length=19) 'dataalt' => string '2016-03-12 07:56:11' (length=19) 'idoperador' => string '0' (length=1) 'controle' => string '1' (length=1)
Usei este código
<?php var_dump($db->data); ?>
28/08/2017
Fabio Rocha
Tente fazer o seguinte:
Troque o seguinte código
if ($db->rows >= 1): $news = $db->data;
Por
if (count($db->data) >= 1): $news = $db->data;
Abraços
Clique aqui para fazer login e interagir na Comunidade :)