I'm working on my own simple blog. I got it working so far only 1 very irritating bug remaining. If I have 4 rows of data in my databse the first 2 (with the lowest ID) won't show up. So if I add a new 3rd row only the first row will pop-up my screen and it will take 2 new posts before the 3rd row will show up. If I turn around the sequence of ID's it does work if I have 2 useless posts in my database. But ofcourse I want the higher id's to show on top.
Here is the code for putting the database info on the screen:
<?php
require('config.inc.php');
require('template.inc.php');
require('functions.inc.php');
include_once('insert.php');
$query="SELECT * FROM blog ORDER BY ID DESC";
$result=mysql_query($query);
$db_field = mysql_fetch_assoc( $result );
mysql_fetch_assoc( $result );
mysql_close();
htmlOpenen('ServerSideBlog');
while ($db_field = mysql_fetch_assoc($result) ) {
echo'
<span class="post">
<h1>'.$db_field['title'].'</h1>
<h2>'.$db_field['date'].'</h2>
<p>'.$db_field['contents'].'</p>
<h3>Hoogachtend, Sincerely, Aufrichtig, sinceramente,</h3>
<h4>'.$db_field['author'].'</h4>
';
}
htmlSluiten();
?>
And here the code for adding the posts in the database:
<?php
$db_host = "db.jxxxxx.com";
$db_username = "md2xxxx230";
$db_pass = "J9xxxx58";
$db_name = "md2xxxxx230";
@mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mysql");
@mysql_select_db("$db_name") or die ("no database");
if ($_POST['parse_var'] == "new"){
$title=$_POST['title'];
$contents=$_POST['contents'];
$author=$_POST['author'];
$date=$_POST['date'];
$date = strftime("%b %d, %y", strtotime($date));
$sqlcreate = mysql_query("INSERT INTO blog (date, title, contents, author)
VALUES(now(),'$title','$contents','$author')");
}
?>
I can't find any solution for the problem... Hope I can get some awnsers here :)