i have written PHP script to display it....but the thing is i cannot able to indent the posts....
following is the HTML version of my data in Message table(copied as HTML and pasted here ..using MySQLFront)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>localhost: test.message</title>
<meta name="GENERATOR" content="MySQL-Front 2.2">
<style type="text/css"><!--
.header {background-color: #C0C0C0;}
th,td {vertical-align: top; background-color: #FFFFFF;}
//--></style>
</head>
<body>
<h3>localhost: test.message (9 Records)</h3>
<table border=1>
<tr class="header">
<th>PostID</th>
<th>Message</th>
<th>PostedBy</th>
<th>ParentID</th>
<th>BranchTutorID</th>
<th>DatePosted</th>
<th>Status</th>
<th>Unit</th>
</tr>
<tr>
<td>1 </td>
<td>Test Post By Tutor </td>
<td>1001022663 </td>
<td>0 </td>
<td>1 </td>
<td>2002-11-03 03:19:27 </td>
<td>A </td>
<td>1 </td>
</tr>
<tr>
<td>2 </td>
<td>Post By Student A </td>
<td>A </td>
<td>1 </td>
<td>1 </td>
<td>2002-11-03 03:42:53 </td>
<td>A </td>
<td>1 </td>
</tr>
<tr>
<td>3 </td>
<td>Post By Student B to A </td>
<td>B </td>
<td>2 </td>
<td>1 </td>
<td>2002-11-03 03:48:11 </td>
<td>A </td>
<td>1 </td>
</tr>
<tr>
<td>4 </td>
<td>Post By Student C to A </td>
<td>C </td>
<td>2 </td>
<td>1 </td>
<td>2002-11-03 03:51:31 </td>
<td>A </td>
<td>1 </td>
</tr>
<tr>
<td>5 </td>
<td>Post By Student D to Tutor </td>
<td>D </td>
<td>1 </td>
<td>1 </td>
<td>2002-11-03 04:05:32 </td>
<td>A </td>
<td>1 </td>
</tr>
<tr>
<td>6 </td>
<td>Post By Student E to Tutor </td>
<td>E </td>
<td>1 </td>
<td>1 </td>
<td>2002-11-03 04:34:53 </td>
<td>A </td>
<td>1 </td>
</tr>
<tr>
<td>7 </td>
<td>Post By Student F to A </td>
<td>F </td>
<td>2 </td>
<td>1 </td>
<td>2002-11-03 05:11:26 </td>
<td>A </td>
<td>1 </td>
</tr>
<tr>
<td>8 </td>
<td>Post By Student G to B </td>
<td>G </td>
<td>3 </td>
<td>1 </td>
<td>2002-11-06 11:58:47 </td>
<td>A </td>
<td>1 </td>
</tr>
<tr>
<td>9 </td>
<td>Post By Student H to C </td>
<td>H </td>
<td>4 </td>
<td>1 </td>
<td>2002-11-06 04:16:48 </td>
<td>A </td>
<td>1 </td>
</tr>
</table>
<br><br>
<i>generated 06/11/2002 11:09:57 PM by <a href="http://www.mysqlfront.de/">MySQL-Front 2.2</a></i>
</body></html>
here is my entire code for this
require('connection.php');
$CurPostID=0;$CurParentID=0;
$PrevPostID=0;$PrevParentID=0;
$TopPos = 3;
$incCounter = 0;
$sSQL = "SELECT * FROM Message WHERE Unit=1 AND BranchTutorID=1 ";
$sSQL .= " ORDER BY PostID,ParentID,DatePosted ";
$ParentResult = mysql_query($sSQL);
$No_Of_Parent_Record = mysql_num_rows($ParentResult);
if($No_Of_Parent_Record >0)
{
$arr_display = array($No_Of_Parent_Record);
while($rsParentResult = mysql_fetch_array($ParentResult))
{
$iPostID = $rsParentResult["PostID"];
$CurPostID = $iPostID;
$sMessage = $rsParentResult["Message"];
$sPostedBy = $rsParentResult["PostedBy"];
$iParentID = $rsParentResult["ParentID"];
$CurParentID = $iParentID;
$iBranchTutorID = $rsParentResult["BranchTutorID"];
$sDatePosted = $rsParentResult["DatePosted"];
$sStatus = $rsParentResult["Status"];
$iUnit = $rsParentResult["Unit"];
if($CurParentID==0)
{
$sValue = "";
$sValue = "<table border=0><tr><td>Posted By: $sPostedBy</td></tr>";
$sValue .= "<tr><td>Date: $sDatePosted</td></tr> <tr><td>$sMessage</td></tr></table><hr>";
echo $sValue;
$arr_display[$incCounter] = $CurPostID;
$incCounter++;
}
else
{
if(in_array($CurPostID,$arr_display))
{
$incCounter = $incCounter;
}
else
{
$sValue = "";
$sValue = "<table border=0><tr><td>Posted By: $sPostedBy</td></tr>";
$sValue .= "<tr><td>Date: $sDatePosted</td></tr> <tr><td>$sMessage</td></tr></table><hr>";
echo $sValue;
$arr_display[$incCounter] = $CurPostID;
$incCounter++;
}
DisplayChild($CurParentID,$CurPostID);
}
}
}
function DisplayChild($iParentID,$iPostID)
{
Global $TopPos;
Global $incCounter;
Global $arr_display;
$sSQL = "";
$sSQL = "SELECT * FROM Message WHERE Unit=1 AND BranchTutorID=1 AND ParentID=$iPostID ";
$sSQL .= " ORDER BY PostID,ParentID,DatePosted";
$ChildResult = mysql_query($sSQL);
$No_Of_Child_Record = mysql_num_rows($ChildResult);
if ($No_Of_Child_Record >0)
{
while($rsChildResult = mysql_fetch_array($ChildResult))
{
$iChildPostID = $rsChildResult["PostID"];
$sChildMessage = $rsChildResult["Message"];
$sChildPostedBy = $rsChildResult["PostedBy"];
$iChildParentID = $rsChildResult["ParentID"];
$iChildBranchTutorID = $rsChildResult["BranchTutorID"];
$sChildDatePosted = $rsChildResult["DatePosted"];
$sChildStatus = $rsChildResult["Status"];
$iChildUnit = $rsChildResult["Unit"];
if(in_array($iChildPostID,$arr_display))
{
$incCounter = $incCounter;
}
else
{
$TopPos = $TopPos + 25;
$sValue = "";
//$sValue = "<div style='position:absolute;left:10%;top:$TopPos%'><table border=0><tr><td>Posted By: $sChildPostedBy</td></tr>";
$sValue = "<table border=0><tr><td>Posted By: $sChildPostedBy</td></tr>";
$sValue .= "<tr><td>Date: $sChildDatePosted</td></tr> <tr><td>$sChildMessage</td></tr></table><hr>";
echo $sValue;
$arr_display[$incCounter] = $iChildPostID;
$incCounter++;
DisplayChild($iChildParentID,$iChildPostID);
}
}
//DisplayChild($iChildParentID,$iChildPostID);
}
}
i used recursive funstion to get the childs....
this will display the posts one by one with parent-child relation but no indentation...
getting the result correctly but donno how to indent the posts(display)based on parent-child relation.. i tried by using div tag..but it is not coming correctly... 😕