Today i'm makeing this new question because this is not posible to display one resu开发者_开发百科lt on a query with limit 10.
Here is the query:
$query = "SELECT * FROM articol WHERE status = 1 ORDER BY data DESC LIMIT 10";
$result = mysql_query($query) or die ("Could not execute query");
while($row = mysql_fetch_array($result))
{
$id = $row["id"];
$titlu = $row["titlu"];
$data = $row["data"];
$desc = $row["continut"];
$part = strip_tags($desc);
}
And this is the echo to display
<link>http://dirlink.ro/articol.php?art_id=<?php echo $id; ?></link>
<title><?php echo $titlu; ?></title>
<description><?php echo substr($part,0,180); ?> ...{Citeste tot} </description>
<pubDate><?php echo $data; ?></pubDate>
The same code is putted on other page, for other category of my website and it's work just fine. I don't understand why at this section is echoing only one result.
All you are doing is reassigning the variables, you are not outputting them, so you will only ever end up outputting the last result.
What you need to do is call them inside the while
loop:
$query = "SELECT * FROM articol WHERE status = 1 ORDER BY data DESC LIMIT 10";
$result = mysql_query($query) or die ("Could not execute query");
while($row = mysql_fetch_assoc($result)) {
$id = $row["id"];
$titlu = $row["titlu"];
$data = $row["data"];
$desc = $row["continut"];
$part = strip_tags($desc);
print "<link>http://dirlink.ro/articol.php?art_id=$id</link>\n"
."<title>$titlu</title>\n"
."<description>".substr($part,0,180)." ...{Citeste tot} </description>\n"
."<pubDate>$data</pubDate>\n";
}
Edited a little after I read the question properly... [blush]
I think you want to use mysql_fetch_assoc($result) for named elements, but I could be mistaken.
your echos need to be in the loop if you are trying to list them all; otherwise your values are going to be overwritten and only the last row will be displayed.
I have fixed it: I checked the RSS field with rssvalidator.org and there it showed me the errors and how to fix it.
So I fixed the error, which seem to originate from some &circi;
, which is a character of a Romanian language.
精彩评论