Hello, I'm trying to make a facebook wall-alike php script.
It loads the posts stuff, photo url and user stuff like username and user id from my MySQL database. It also checks if the post is just a comment to another post (parentof). I can present all the original posts with pictures with a simple do-while using <table> tags .
But how could I present the comments under every post? I guess with another do-loop, but how?
Here is my code:
<?php
require_once "config.php";
$result = mysql_query('SET NAMES utf8');
$result = mysql_query('SET CHARACTER SET utf8');
$wallhaku = mysql_query("SELECT `wall`.`post_id`, `wall`.`parentof`, `wall`.`sentby`, `wall`.`text`, `wall`.`image_url`, `users`.`username`, `users`.`photopath`, `users`.`name`, `users`.`member_id` FROM `wall` LEFT JOIN `users` ON `wall`.`sentby` = `users`.`member_id` WHERE parentof=0 ORDER BY post_id DESC") or die (mysql_error());
$row_wallhaku = mysql_fetch_array($wallhaku);
?>
<table width="800" height="120" border="0" cellpadding="10">
<?php $i=0; $numberpage=1;
do {
$wallid = $row_wallhaku['post_id'];
$parenthaku = mysql_query("SELECT post_id, parentof FROM wall WHERE parentof=$wallid") or die (mysql_error());
$row_parenthaku = mysql_num_rows($parenthaku);
if($i%$numberpage==0) echo "<tr>";?>
<td width="120" align="left">
<img src=<?php echo $row_wallhaku['photopath']; ?> height= "100" width="100">
</td>
<td width="600" align="left">
<a href="member.php?id=<?php echo $row_wallhaku['member_id']; ?>"><?php echo $row_wallhaku['name']?></a><br /><p><?php echo $row_wallhaku['text'];
if($row_wallhaku['image_url']=="0") {
?>
<p align="right"><?php echo $row_parenthaku ?> kommenttia. <a href="post.php?id=<?php echo $row_wallhaku['post_id']; ?>">Lue, kommentoi</a> <?php } ?></td>
<?php $i++; if($i%$numberpage==0) echo "</tr>";
if($row_wallhaku['image_url']!="0")
{
?>
<tr>
<td width='800' colspan='2' align='center'>
<a href="post.php?id=<?php echo $row_wallhaku['post_id']; ?>"><img src=<?php echo $row_wallhaku['image_url']; ?> height="180"></a>
<p align="right"><?php echo $row_parenthaku ?> kommenttia. <a href="post.php?id=<?php echo $row_wallhaku['post_id']; ?>">Lue, kommentoi</a>
</td>
</tr>
<?php
}
?>
<?php } while ($row_wallhaku = mysql_fetch_assoc($wallhaku)); ?>
</table>