Forums Archive Index > Cool free scripts > MySQL - PHP and Newsticker - records repeating
Date: 24 Oct 2005 1:46 pm
Hello, I am using MySQL and PHP to show press relases using the newsticker script.
After going to this post: --> http://www.smartmenus.org/forum/viewtopic.php?t=307
I managed to have it working.
However despite that it shows the records, it does not show them in order and repeats the first one sometimes even 5 times before showing the others.
This is not an error in my query because when I fetch the records in a plain php file, i shows them in order and does not repeat any.
What can be causing the problem?
Thanks a lot, again...
:lol:
Date: 24 Oct 2005 2:29 pm
Could you please post a link to a sample? I would like to take a look at the code. It looks like an issue with the SQL query to me but you said you are sure it's not, so I am a bit confused and I think I should take a look at the code.
Thanks!
Date: 24 Oct 2005 2:39 pm
Hello, thanks for your reply, here is the code I am using to output the query results using the newsticker...
Code:
v_content=[
<?php
$ticker_output = "";
if (mysql_num_rows($prensa) > 0) {
while($resultados = mysql_fetch_array($prensa))
echo //missing echo statement
$ticker_output.="['$url/usuario/contenido/prensa/documentos/docpr_documento.php?id=$resultados[id]','".htmlentities(stripslashes(trim($resultados[titulo])))."<br><span class=\"ltr-rosa\">".$resultados[diaid]." ".$resultados[mes2]." ".$resultados[ano]."</span>','_self'],";
echo $ticker_output = substr($ticker_output,0,-1); // removes the last comma
} else {
mysql_close($connection);
}
?>
];
I do not know if this helps, but here is the sql query as well:
Code:
$query = "SELECT sp_documentos.id, sp_documentos.titulo, sp_documentos.fecha, sp_documentos.id_ano, sp_documentos.id_mes, sp_documentos.id_dia, diaid, mes2, ano FROM sp_documentos, cm_anos, cm_meses, cm_dias WHERE id_ano = anoid AND id_mes = mesid AND id_dia = diaid ORDER BY sp_documentos.id_ano desc, sp_documentos.id_mes desc, sp_documentos.id_dia desc LIMIT 0,5";
$prensa = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
Thanks a lot.. :lol:
Date: 24 Oct 2005 2:42 pm
Hm, it looks OK. :?
Could I please take a look at an example page with the PHP output?
Date: 24 Oct 2005 3:23 pm
Yeah, sure... take a look to either of these pages:
--> http://www.maximilianoalexander.com/usuario/contenido/prensa/documentos/docpr_buscar.php
and/or
--> http://www.maximilianoalexander.com/usuario/contenido/acerca/galeria/galeria_buscar.php
Actually you will notice your script through out the site... :D
Thanks
Date: 24 Oct 2005 3:42 pm
smartmenus wrote:
Hm, it looks OK. :?
WOW! Sorry but I just looked at the SQL query code and didn't pay attention to the PHP code above it at all.
The PHP code doesn't look OK. It should be like this:
Code:
v_content=[
<?php
$ticker_output = "";
if (mysql_num_rows($prensa) > 0) {
while($resultados = mysql_fetch_array($prensa))
$ticker_output.="['$url/usuario/contenido/prensa/documentos/docpr_documento.php?id=$resultados[id]','".htmlentities(stripslashes(trim($resultados[titulo])))."<br><span class=\"ltr-rosa\">".$resultados[diaid]." ".$resultados[mes2]." ".$resultados[ano]."</span>','_self'],";
$ticker_output = substr($ticker_output,0,-1); // removes the last comma
echo $ticker_output;
} else {
mysql_close($connection);
}
?>
];
Please try replacing your current code with the above and let me know if you still have any problems. But I think this should fix the issue.
PS:Sorry once again for my mistake!
Date: 24 Oct 2005 4:05 pm
Great, it works perfectly now... thanks :lol:
Although I do not quite understand why you removed the echo statements, what was the problem???
Was the first echo printing the query with the comma and the second without it, that is why it repeated the first record 3 or more times??? :shock:
Best
Date: 24 Oct 2005 4:27 pm
Yep, the first echo in your code would output the value of the $ticker_output variable each time it is concatenated in the while cycle. That's why I removed it.
Date: 24 Oct 2005 6:03 pm
I C, well thanks for all the help... the script is really useful... congrats
Take care :wink: