PF2G Posted July 6, 2012 at 02:39 PM Report #467703 Posted July 6, 2012 at 02:39 PM Boas, eu quero organizar a noticias por data, mas so que apareça as noticias do dia de hoje e mais antigas. Estou a usar o CURDATE(), mas não acontece nada, o que é que estou a fazer de mal? if ($hj_antes) { echo "<h1 class='title' style='padding-top:10px;'>". $desc_atual['titulo']. "<div class='escrit' style='margin-top:-20px;'>"; if (mysql_num_rows($query_not_ant)>0) { echo "<a href='".$current_lang."/".$module."/".$id_ant."'>< ANTERIOR</a>"; } else { echo "< ANTERIOR"; } echo " "; if (mysql_num_rows($query_next)>0) { echo "<a href='".$current_lang."/".$module."/".$id_nxt."'>SEGUINTE ></a>"; } else { echo "SEGUINTE >"; } echo "</div> </h1>"; echo '<div class="details">'; echo '<div class="descricao" style="margin:0 15px 0px">'. $desc_atual['descricao'] .'</div>'; echo '</div>'; }
MASNathan Posted July 6, 2012 at 04:33 PM Report #467731 Posted July 6, 2012 at 04:33 PM Boas, eu quero organizar a noticias por data, mas so que apareça as noticias do dia de hoje e mais antigas. Estou a usar o CURDATE(), mas não acontece nada, o que é que estou a fazer de mal? if ($hj_antes) { echo "<h1 class='title' style='padding-top:10px;'>". $desc_atual['titulo']. "<div class='escrit' style='margin-top:-20px;'>"; if (mysql_num_rows($query_not_ant)>0) { echo "<a href='".$current_lang."/".$module."/".$id_ant."'>< ANTERIOR</a>"; } else { echo "< ANTERIOR"; } echo " "; if (mysql_num_rows($query_next)>0) { echo "<a href='".$current_lang."/".$module."/".$id_nxt."'>SEGUINTE ></a>"; } else { echo "SEGUINTE >"; } echo "</div> </h1>"; echo '<div class="details">'; echo '<div class="descricao" style="margin:0 15px 0px">'. $desc_atual['descricao'] .'</div>'; echo '</div>'; } 1 - Tens noticias do futuro que não queres mostrar? 2 - No código que tens ai não existe qualquer menção do curdate(), queres que nós adivinhemos o que fizeste antes? 3 - é que nem dá pra saber o que é que cada variável tem
PF2G Posted July 6, 2012 at 04:39 PM Author Report #467733 Posted July 6, 2012 at 04:39 PM 1 - Tens noticias do futuro que não queres mostrar? 2 - No código que tens ai não existe qualquer menção do curdate(), queres que nós adivinhemos o que fizeste antes? 3 - é que nem dá pra saber o que é que cada variável tem Desculpa copiei mal o codigo: $query_noticia=mysql_query("SELECT n.posicao, n.id, nl.titulo, nl.descricao FROM noticias as n, noticias_lang as nl WHERE n.id = '".$clean_url[2]."' AND nl.lang='$current_lang' AND n.visivel=1 AND nl.visivel=1 GROUP BY nl.lang"); $rows_noticias = mysql_num_rows($query_noticia); if($rows_noticias >0) { echo "<div class='content_page'>"; echo "<div class='content_page_top'></div>"; echo "<div class='content_page_center'>"; while($row_noticia = mysql_fetch_object($query_noticia)) { /***********************************************************/ $query_registos = mysql_query("SELECT * FROM noticias") or die(mysql_error()); $total_registos = mysql_num_rows($query_registos); $query_id_reg=mysql_query("SELECT * FROM noticias WHERE id='".$row_noticia->id."'") or die(mysql_error()); $id_reg=mysql_fetch_assoc($query_id_reg); $query_desc_atual=mysql_query("SELECT * FROM noticias_lang WHERE id_noticia='".$id_reg['id']."'") or die(mysql_error()); $desc_atual=mysql_fetch_assoc($query_desc_atual); /***********************************************************/ $posicao=$id_reg['posicao']; $posicao_anterior=$posicao-1; $query_not_ant=mysql_query("SELECT * FROM noticias WHERE posicao='".$posicao_anterior."' AND visivel=1") or die(mysql_error); $not_ant=mysql_fetch_assoc($query_not_ant); $id_ant=$not_ant['id']; $query_desc=mysql_query("SELECT * FROM noticias_lang WHERE id_noticia='".$not_ant['id']."' AND visivel=1") or die(mysql_error()); $desc=mysql_fetch_assoc($query_desc); $posicao_nxt=$posicao + 1; $query_next=mysql_query("SELECT * FROM noticias WHERE visivel=1 AND posicao='".$posicao_nxt."'") or die (mysql_error()); $next=mysql_fetch_assoc($query_next); $id_nxt=$next['id']; $query_nxt_titulo=mysql_query("SELECT * FROM noticias_lang WHERE id_noticia='".$next['id']."' AND visivel=1") or die(mysql_error()); $nxt_titulo=mysql_fetch_assoc($query_nxt_titulo); $link = mysql_query("SELECT id, str_to_date(data,'%d/%m%/%Y') AS date FROM noticias WHERE data <= CURDATE() ORDER BY data") or die(mysql_error()); $row = mysql_fetch_assoc($link); echo "<h1 class='title' style='padding-top:10px;'>". $desc_atual['titulo']. "<div class='escrit' style='margin-top:-20px;'>"; if (mysql_num_rows($query_not_ant)>0) { echo "<a href='".$current_lang."/".$module."/".$id_ant."'>< ANTERIOR</a>"; } else { echo "< ANTERIOR"; } echo " "; if (mysql_num_rows($query_next)>0) { echo "<a href='".$current_lang."/".$module."/".$id_nxt."'>SEGUINTE ></a>"; } else { echo "SEGUINTE >"; } echo "</div> </h1>"; echo '<div class="details">'; echo '<div class="descricao" style=" margin-left:15px; padding-bottom:15px;">'. $desc_atual['descricao'] .'</div>'; echo '</div>'; echo '<div class="clearfloat"></div>'; echo '</div>'; echo "<div class='content_page_bottom'></div>"; echo "</div>"; } }
MASNathan Posted July 6, 2012 at 04:51 PM Report #467737 Posted July 6, 2012 at 04:51 PM Desculpa copiei mal o codigo: continuas sem responder há minha 1ª pergunta
PF2G Posted July 6, 2012 at 04:54 PM Author Report #467738 Posted July 6, 2012 at 04:54 PM Tenho!!! E estao a aparecer
yoda Posted July 6, 2012 at 05:18 PM Report #467746 Posted July 6, 2012 at 05:18 PM Não terás queries a mais? before you post, what have you tried? - http://filipematias.info sense, purpose, direction
PF2G Posted July 6, 2012 at 05:22 PM Author Report #467751 Posted July 6, 2012 at 05:22 PM Penso que nao...tirando a que crescentei agora (CRUDATE), as outras sao para calcular a posicao fazendo dois botoes um para redirecionar para a posicao seguinte e outro para a posicao anterior. Agora so queria acrescentar este promenor de aparecer so as noticias de hoje ou mais antigas...
PF2G Posted July 9, 2012 at 08:57 AM Author Report #467999 Posted July 9, 2012 at 08:57 AM Bom dia, estive a ver melhor e alterei um pouco as coisas, mas apresenta-me na mesma as noticias do "futuro". Alguem me pode ajudar, sff? $query_noticia=mysql_query("SELECT n.posicao, n.id, nl.titulo, nl.descricao FROM noticias as n, noticias_lang as nl WHERE n.id = '".$clean_url[2]."' AND nl.lang='$current_lang' AND n.visivel=1 AND nl.visivel=1 GROUP BY nl.lang"); $rows_noticias = mysql_num_rows($query_noticia); if($rows_noticias >0) { echo "<div class='content_page'>"; echo "<div class='content_page_top'></div>"; echo "<div class='content_page_center'>"; while($row_noticia = mysql_fetch_object($query_noticia)) { /********************* DATA -> CURDATE *********************/ $query_data = mysql_query("SELECT * FROM noticias WHERE data <= CURDATE() ORDER BY data ASC") or die(mysql_error()); $data = mysql_fetch_assoc($query_data); /***********************************************************/ $query_registos = mysql_query("SELECT * FROM noticias WHERE data='".$data['data']."'") or die(mysql_error()); $total_registos = mysql_num_rows($query_registos); $query_id_reg=mysql_query("SELECT * FROM noticias WHERE id='".$row_noticia->id."'") or die(mysql_error()); $id_reg=mysql_fetch_assoc($query_id_reg); $query_desc_atual=mysql_query("SELECT * FROM noticias_lang WHERE id_noticia='".$id_reg['id']."'") or die(mysql_error()); $desc_atual=mysql_fetch_assoc($query_desc_atual); /***********************************************************/ $posicao=$id_reg['posicao']; $posicao_anterior=$posicao-1; $query_not_ant=mysql_query("SELECT * FROM noticias WHERE posicao='".$posicao_anterior."' AND visivel=1") or die(mysql_error); $not_ant=mysql_fetch_assoc($query_not_ant); $id_ant=$not_ant['id']; $query_desc=mysql_query("SELECT * FROM noticias_lang WHERE id_noticia='".$not_ant['id']."' AND visivel=1") or die(mysql_error()); $desc=mysql_fetch_assoc($query_desc); $posicao_nxt=$posicao + 1; $query_next=mysql_query("SELECT * FROM noticias WHERE visivel=1 AND posicao='".$posicao_nxt."'") or die (mysql_error()); $next=mysql_fetch_assoc($query_next); $id_nxt=$next['id']; $query_nxt_titulo=mysql_query("SELECT * FROM noticias_lang WHERE id_noticia='".$next['id']."' AND visivel=1") or die(mysql_error()); $nxt_titulo=mysql_fetch_assoc($query_nxt_titulo); echo "<h1 class='title' style='padding-top:10px;'>". $desc_atual['titulo']. "<div class='escrit' style='margin-top:-20px;'>"; if (mysql_num_rows($query_not_ant)>0) { echo "<a href='".$current_lang."/".$module."/".$id_ant."'>< ANTERIOR</a>"; } else { echo "< ANTERIOR"; } echo " "; if (mysql_num_rows($query_next)>0) { echo "<a href='".$current_lang."/".$module."/".$id_nxt."'>SEGUINTE ></a>"; } else { echo "SEGUINTE >"; } echo "</div> </h1>"; echo '<div class="details">'; echo '<div class="descricao" style=" margin-left:15px; padding-bottom:15px;">'. $desc_atual['descricao'] .'</div>'; echo '</div>'; echo '<div class="clearfloat"></div>'; echo '</div>'; echo "<div class='content_page_bottom'></div>"; echo "</div>"; } }
MASNathan Posted July 9, 2012 at 09:09 AM Report #468002 Posted July 9, 2012 at 09:09 AM mas como é que tens noticias do futuro lol?
HappyHippyHippo Posted July 9, 2012 at 09:16 AM Report #468004 Posted July 9, 2012 at 09:16 AM quando é necessário efetuar 9 query's para apresentar qualquer coisa, algo deve estar muito mal. não me venhas perguntar o que é porque impossível perceber o que estás p'raí a tentar fazer IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
PF2G Posted July 9, 2012 at 11:26 AM Author Report #468032 Posted July 9, 2012 at 11:26 AM Tenho este codigo mais pequeno, talvez seja melhor... O que eu estou a fazer é selecionar as noticias cuja data <= CURDATE(), não deveria resultar? <?php $row_noticias = getRows("SELECT n.id, n.data, str_to_date(n.data, '%d/%m/%Y') AS date, nl.id_noticia, nl.titulo, nl.descricao, nl.resumo FROM `noticias` as n, `noticias_lang` as nl WHERE n.id = nl.id_noticia AND n.data <= CURDATE() AND nl.lang='$current_lang' AND n.visivel=1 AND nl.visivel=1 ORDER BY date DESC LIMIT 1"); foreach($row_noticias as $key => $noticia){ echo "<label>".formatdate($noticia['data'])."</label>"; echo "<a href='".$current_lang."/noticia/".$noticia['id_noticia']."'>".get_substr($noticia['resumo'], 140)."</a>"; } ?>
laeknishendr Posted July 11, 2012 at 11:27 PM Report #468421 Posted July 11, 2012 at 11:27 PM PF2G, você precisa de uma coluna que salve a data em que a notícia foi postada e fazer um sql com o order baseado nisso, eu digo: SELECT * FROM noticias WHERE noiticia = 1 ORDER BY data_postagem DESC;
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now