Hi,
I forund a free forum script online. Now I would like to show on my frontpage the latest post and link to the post.
It lshould show this:
Title
name
Texst (max 100 string)
date and time
I have succeded in this to some extent... If the latest post is a reply then I would like it to show the title of the parent post. The db is made so that if it's not a thread but a reply then it gets a parent value that matches the id of the parent. If it's a new thread the parent gets a value of 0.
I come along way considering my low programming skills. I have come so far
If its a new thread (parent = 0) then it shows just fine.
However if its a new reply (parent = id for the thread commented) I can only make it show like this
Name
Tekst (max 100 string)
Date and time
Title
Apparently my coding is not that good because I'm not able to show the new reply's parent title on the top. Whatever I try it dosent work.
PLEASE HELP ME!
My code looks like this:
==================START OF CODE=============================
<?php
function cut($str,$size=99){
if(strlen($str) > $size){
$str = substr($str, 0, $size)."...";
}
return $str;
}
?>
<?php
include('config.php');
$q = mysql_query("SELECT name,message,id,header,parent,date_format(date, '%d-%m/%H:%i') AS date FROM bkforum ORDER BY id DESC LIMIT 1") or die(mysql_error());
while($r = mysql_fetch_array($q)){
if ($r[parent] == 0) {
echo "<b><a href='laes.php?id=$r[id]'>$r[header]</a></b><br>";
echo "<i>Af " . $r['name'] . "</i>:<br />" ;
echo cut($r['message']);
echo "<br />(" . $r['date'] . ")" ;
} else {
include('config.php');
$q = mysql_query("SELECT name,message,id,header,parent,date_format(date, '%d-%m/%H:%i') AS date FROM bkforum ORDER BY id DESC LIMIT 1") or die(mysql_error());
while($r = mysql_fetch_array($q)){
echo "<br><b>$na</b>" ;
echo "<a href='laes.php?id=$r[parent]'> Overskrift<br>Af " . $r['name'] . ":<br>" . cut($r['message']) . "<br>(" . $r['date'] . ")</a>";
$np = $r[parent] ;
$query = mysql_query("SELECT id,header,message,name,DATE_FORMAT(date,'%e/%c-%y %T') AS id FROM bkforum WHERE id = $np ORDER BY id DESC LIMIT 1") or die(mysql_error());
if (mysql_num_rows($query) == 0) {
echo 'Der er ingen tråde i forummet!<br>';
} else {
while($row = mysql_fetch_assoc($query)) {
$na = $row[header] ;
echo "<br><b>$na</b>" ;
}
}
}
}
}
?>
======================END OF CODE=========================