Bom dia!
Pessoal preciso desenvolver uma paginação estilo do facebook para um cliente. Acontece que alem do id da postagem preciso tb incluir um outro parâmetro id_cat (onde este seleciona a categoria da notícia). Atualmente o código funciona mas não consegue imprimir a categoria na página do AJAX.
$query="select * from tb_noticias where id>'$lastmsg' AND id_cat='$id_cat' order by id asc limit 5";
SEGUE EM SEQUÊNCIA:
Tabela do banco de dados
e os 2 arquivos php
noticias.php aquivo principal e
facebook_style_ajax_more.php (ONDE ESTÁ O PROBLEMA DE NÃO IMRIMIR O $id_cat
E database_connection.php (CONECTA AO BD)
EU TENTEI ADAPTAR O SCRIPT DO SITE: http://youhack.me/2010/05/14/an-alternative-to-pagination-facebook-and-twitter-style
AGRADEÇO ANTECIPADO A AJUDA!
SQL:
--
-- Estrutura da tabela `tb_noticias`
--
CREATE TABLE IF NOT EXISTS `tb_noticias` (
`id` int(5) NOT NULL auto_increment,
`id_cat` char(4) NOT NULL,
`prioridade` varchar(25) NOT NULL,
`data` datetime NOT NULL default '0000-00-00 00:00:00',
`data2` datetime NOT NULL default '0000-00-00 00:00:00',
`titulo` text NOT NULL,
`subtitulo` text,
`texto` text NOT NULL,
`foto` varchar(255) default NULL,
`fotos_extras` enum('S','N') NOT NULL default 'N',
`alinhamento_foto` enum('L','R') NOT NULL default 'L',
`largura_foto` char(3) NOT NULL default '250',
`altura_foto` char(3) NOT NULL default '',
`status` enum('S','N') NOT NULL default 'S',
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=70 ;
----------------------------------------------------------------------------------------------------- fim ---------------------------------
NOTÍCIAS.PHP
<?php
include('database_connection.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>An Alternative to pagination : Facebook Style</title>
<script type="text/javascript" src="/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$(function() {
$('.load_more').live("click",function() {
var last_msg_id = $(this).attr("id");
if(last_msg_id!='end'){
$.ajax({
type: "POST",
url: "/paginas/facebook_style_ajax_more.php",
data: "lastmsg="+ last_msg_id,
beforeSend: function() {
$('a.load_more').append('<img src="/layout/facebook_style_loader.gif" />');
},
success: function(html){
$(".facebook_style").remove();
$("ol#updates").append(html);
}
});
}
return false;
});
});
</script>
<style>
body {
font-family:Arial, 'Helvetica', sans-serif;
color:#000;
font-size:15px;
}
a {
color:#2276BB;
text-decoration:none;
}
* {
margin:0px;
padding:0px
}
ol.row {
list-style:none
}
ol.row li {
position:relative;
border-bottom:1px solid #EEEEEE;
padding:8px;
}
ol.row li:hover {
background-color:#F7F7F7;
}
ol.row li:first-child {
}
#container {
margin-left:0px;
width:600px
}
img {
border : none ;
}
#facebook_style {
border:1px solid #D8DFEA;
padding:10px 15px;
background-color:#EDEFF4;
}
#facebook_style a {
color:#3B5998;
cursor:pointer;
text-decoration:none;
font-family:"lucida grande",tahoma,verdana,arial,sans-serif;
font-size:11px;
text-align:left;
}
</style>
</head>
<body>
<div id='container'>
<ol class="row" id="updates">
<?php
$query ="select * from tb_noticias WHERE status='S' HAVING id_cat='$id_cat' ORDER BY id asc LIMIT 5";
$result = mysqli_query($dbc,$query);
while($dados=mysqli_fetch_array($result,MYSQLI_ASSOC))
{
$msg_id=$dados['id'];
$message=$dados['titulo'];
$id_cat=$dados['id_cat'];
?>
<li>
<a href="<?="/noticia/$msg_id/";?>" target="_parent">
<?php echo $message; ?>
</a>
</li>
<?php } ?>
</ol>
<div class="facebook_style" id="facebook_style">
<a id="<?php echo $msg_id; ?>" href="#" class="load_more" >Show Older Posts <img src="/layout/arrow1.png" /> </a>
</div>
</div>
</body>
</html>
----------------------------------------------------------------------------------------------------- fim ---------------------------------
facebook_style_ajax_more.php (ONDE TA O PROBLEMA DE não LER O ID_CAT)
<HTML>
<HEAD>
<TITLE></TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</HEAD>
<BODY>
<?php
include('database_connection.php');
if(isset($_POST['lastmsg']) &&is_numeric($_POST['lastmsg']))
{
$lastmsg=$_POST['lastmsg'];
$query="select * from tb_noticias where id>'$lastmsg' AND id_cat='$id_cat' order by id asc limit 5";
$result = mysqli_query($dbc,$query);
while($dados=mysqli_fetch_array($result,MYSQLI_ASSOC))
{
$msg_id=$dados['id'];
$message=$dados['titulo'];
$id_cat=$dados['id_cat'];
?>
<li>
<a href="<?="/noticia/$msg_id/";?>" target="_parent">
<?php echo $message; ?>
</a>
</li>
<?php
}
?>
<?php
if( mysqli_num_rows($result)==5){
?>
<div class="facebook_style" id="facebook_style"> <a id="<?php echo $msg_id; ?>" href="#" class="load_more" >Show Older Posts <img src="/layout/arrow1.png" /></a> </div>
<?php
}else {
echo ' <div id="facebook_style">
<a id="end" href="#" class="load_more" >No More Posts</a>
</div>';
}
}
?>
</BODY>
</HTML>
----------------------------------------------------------------------------------------------- FIM ----------------------------------------------------
database_connection.php COM O BD
<?php
/*Define constant to connect to database */
DEFINE('DATABASE_USER', 'liber958_2014');
DEFINE('DATABASE_PASSWORD', 'liber958_2014');
DEFINE('DATABASE_HOST', 'localhost');
DEFINE('DATABASE_NAME', 'liber958_2014');
// Make the connection:
$dbc = @mysqli_connect(DATABASE_HOST, DATABASE_USER, DATABASE_PASSWORD,
DATABASE_NAME);
if (!$dbc) {
trigger_error('Could not connect to MySQL: ' . mysqli_connect_error());
}
?>