Jump to content

[Resolvido] Noticias de hoje e antigas


PF2G

Recommended Posts

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."'>&lt ANTERIOR</a>";
    }
    else
    {
	 echo "&lt ANTERIOR";
    }

    echo "   ";

    if (mysql_num_rows($query_next)>0)
    {
	 echo "<a href='".$current_lang."/".$module."/".$id_nxt."'>SEGUINTE &gt</a>";
    }
    else
    {
	 echo "SEGUINTE &gt";
    }

   echo "</div> </h1>";
 echo '<div class="details">';
   echo '<div class="descricao" style="margin:0 15px 0px">'. $desc_atual['descricao'] .'</div>';
 echo '</div>';
   }
Link to comment
Share on other sites

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."'>&lt ANTERIOR</a>";
	}
	else
	{
	 echo "&lt ANTERIOR";
	}

	echo "   ";

	if (mysql_num_rows($query_next)>0)
	{
	 echo "<a href='".$current_lang."/".$module."/".$id_nxt."'>SEGUINTE &gt</a>";
	}
	else
	{
	 echo "SEGUINTE &gt";
	}

   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

Link to comment
Share on other sites

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."'>&lt ANTERIOR</a>";
}
else
{
echo "&lt ANTERIOR";
}

echo "   ";

if (mysql_num_rows($query_next)>0)
{
echo "<a href='".$current_lang."/".$module."/".$id_nxt."'>SEGUINTE &gt</a>";
}
else
{
echo "SEGUINTE &gt";
}

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>";
}
}
Link to comment
Share on other sites

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."'>&lt ANTERIOR</a>";
   }
   else
   {
    echo "&lt ANTERIOR";
   }

   echo "   ";

   if (mysql_num_rows($query_next)>0)
   {
    echo "<a href='".$current_lang."/".$module."/".$id_nxt."'>SEGUINTE &gt</a>";
   }
   else
   {
    echo "SEGUINTE &gt";
   }	  
 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>";
  }
 }
Link to comment
Share on other sites

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>";
 }
   ?>
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.