Hi folks,
Just a quickie. I'm extracting posts from a simple forum and have managed to extract the last 10 posts listed by subject. However, what I really want is to list the last 10 threads and not posts.
To do this, I need to tell the script to only print out the subject line when the pid for that posts is equal to 0.
I currently have:
<?
// connect to mysql and select database
$db = mysql_pconnect("localhost","databasename","password");
mysql_select_db("database",$db);
// build the query, order by newest ID and limit it to 10
$sql = "select * from forum_table order by id desc limit 10";
// run the query and set a result identifier to the recordset
$res = mysql_query($sql);
// loop the recordset
while ($article = mysql_fetch_array($res)) {
// this sticks the results row by row into an array called $article. rows are called via $array["COLUMN"]
echo ''.$article["subject"].'<br>';
}
?>
Now, as I say, this works fine but lists duplicate posts if more than one person replies to it.
Can I include an if statement or something so that when I run the query I tell the script to only print the subject with a pid==0 ??