I'm trying to create an atom feed for my blog after ditching blogger a while back, and have come across a problem I don't understand. Basically I am confused regarding a mysql query, when I run it in my db it works but when I do so in a file it doesnt. The query is [SIZE=2]SELECT id, filename, title, date_format(date_time, '%Y-%m-%dT%TZ') as stamped, content, poster_id FROM `blog_cat` ORDER BY id DESC LIMIT 0,10[/SIZE] Code (markup): You can see this returns 10 results here. On atom.xml and atom.php it does not. I am using the following code in atom.php <?php require_once("./file.php"); $connect = @mysql_connect(CONNECT_HOST,CONNECT_USERNAME,CONNECT_PASSWORD) or die ("Could not connect to the host server"); $database = @mysql_select_db(DB_USERNAME) or die ("Could not connect to the database"); $select_posts = @mysql_query("SELECT id, filename, title, date_format(date_time, '%Y-%m-%dT%TZ') as stamped, content, poster_id FROM `blog_cat` ORDER BY id DESC LIMIT 0,10") or die ("Could not select the post"); $i = 0; while( $r=@mysql_fetch_array($select_posts) ) { $i++; $r = @mysql_fetch_array($select_posts); $id = $r["id"]; $url = $r["filename"]; $title = htmlspecialchars($r["title"]); $time = $r["stamped"]; $content = $r["content"]; $author = $r["poster_id"]; if ($i == 1) { $f_time = $time; } if ($i == 1) { $f_id = $id; } switch ($author) { case 1: $author_name = "Piniyini"; break; case 2: $author_name = "Boba"; break; case 3: $author_name = "Khia"; break; } $healthy = array("'", '"', "&"); $yummy = array(" ", " ", " "); $newphrase = str_replace($healthy, $yummy, strip_tags($content) ); $newphrase = htmlspecialchars($newphrase); $message .= <<<MSG <entry xmlns="http://purl.org/atom/ns#"> <link href="http://www.toseef.com/$url" rel="service.edit" title="$title"/> <author> <name>$author_name</name> </author> <issued>$time</issued> <modified>$time</modified> <created>$time</created> <link href="http://www.toseef.com/$url" rel="alternate" title="$title" type="text/html"/> <id>tag:toseef.com,2005:blog-toseef.post-$id</id> <title mode="escaped" type="text/html">$title</title> <content type="application/xhtml+xml" xml:base="http://www.toseef.com" xml:space="preserve"> <div xmlns="http://www.w3.org/1999/xhtml">$newphrase</div> </content> <draft xmlns="http://purl.org/atom-blog/ns#">false</draft> </entry> MSG; } @mysql_free_result($select_posts); @mysql_close($connect); echo('<pre> '.htmlspecialchars($message).' </pre>'); ?> PHP: Erm ... any takers?
Looks like its because you're calling mysql_fetch_array twice right after each other. Once in the while condition, and then a couple of lines after that again. That means you're basically only showing half the results. You don't need the second one. Leave the following: while( $r=@mysql_fetch_array($select_posts) ) PHP: Take out the following on line 10 of your code: $r = @mysql_fetch_array($select_posts); PHP: