Pesquisar na Comunidade
Mostrando resultados para as tags ''selecionar post anterior e próximo no mysql''.
Encontrado 1 registro
-
php Selecionar post anterior e próximo no MySQL
Juliana~* postou um tópico no fórum em Outras linguagens WEB
No MySQL não temos um comando para obter o post anterior então tem q ser no PHP. Até consegui com substring mas achei complicado de mais e não consegui resolver meu problema. Quem tiver com problemas e procurar no Google vai achar aqui então :* <?php $string_url_type_all = 'tipo = :curso AND categoria = :cat AND id = :id'; $string_url_type_nId = 'tipo = :curso AND categoria = :cat'; if (isset($_GET['ttt'])) { // javascript post $a = $_GET['t']; $b = $_GET['tt']; $c = (int)$_GET['ttt']; $f = $db->prepare('SELECT tipo,categoria,id,titulo FROM post WHERE '.$string_url_type_nId.' ORDER BY id ASC'); $f->bindParam(':curso',$a); $f->bindParam(':cat',$b); $h = null; $post_anterior = null; $proximo_post = null; if ($f->execute()) { if ($f->rowCount() > 0 ) { $g = true; $h = $f->fetchAll(PDO::FETCH_NUM); for ($a_ = 0; $a_ < count($h); $a_++) { // post atual if ( $h[$a_][2] == $c ) { // post anterior //var_dump($h[$a_ - 1]); if ( isset ( $h[$a_ - 1] ) ) for ($c_ = 0; $c_ < count($h[$a_ - 1]); $c_++) { $post_anterior = $post_anterior.$h[$a_ - 1][$c_].'|'; } else $post_anterior = 0; // proximo post if ( isset ( $h[$a_ + 1] ) ) for ($c_ = 0; $c_ < count($h[$a_ + 1]); $c_++) { $proximo_post = $proximo_post.$h[$a_ + 1][$c_].'|'; } else $proximo_post = 0; break; } } } } ?> <div id="more_post"> <div class="post_x post_anterior"> <?php if ($g && $post_anterior != '0') { $h = explode('|',$post_anterior); ?> <span class="post_x_span">Artigo Anterior</span><br /> <a href="<?php echo $local.$h[0].'/'.$h[1].'/'.$h[2].'/'; ?>"><?php echo $h[3] ?></a> <?php } else { ?> <span>Esse é o primeiro post :)</span> <?php } ?> </div>
