我想製作一個類似facebook的php腳本。如何在Facebook之類的帖子下顯示評論呢?
它從我的MySQL數據庫加載帖子的東西,照片的網址和用戶的東西,如用戶名和用戶ID。它還檢查帖子是否僅僅是對另一帖子(parentof)的評論。我可以用簡單的do-while使用標籤來呈現所有原始帖子。
但是我怎麼能在每一篇文章中提出評論?我想用另一個do循環,但是如何?
這裏是我的代碼:
<?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);
<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
}
</table>
把代碼放在那裏給你。要插入代碼,可以縮進4個空格,或使用編輯器上的{}圖標,或使用反引號('或alt + 096)。不是一個解決方案,但你有沒有嘗試過[disqus](http://disqus.com)?這與jQuery api網站上使用的相同,以舉例說明;那會爲你節省很多工作! – 2012-02-04 14:08:21
因此,代碼只是逐行檢查帖子,並檢查它是否附有圖片。如果它有敵人,它會在帖子後張貼一張圖片。 – 2012-02-04 14:09:54
是的,謝謝你把它放在這裏! – 2012-02-04 14:10:24