Created
November 27, 2013 14:35
-
-
Save amin007/7676669 to your computer and use it in GitHub Desktop.
masukkan sql dalam tatasusunan lepas itu baru echo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include 'connect.php'; | |
include 'header.php'; | |
// mula2 buat sql dan masuk dalam tatasusunan dahulu | |
$sql = "SELECT | |
topik_id, | |
topik_subjek | |
FROM | |
forum_topik | |
WHERE | |
forum_topik.topik_id = " . mysql_real_escape_string($_GET['id']); | |
$result = mysql_query($sql); | |
// masuk dalam tatasusunan | |
$senaraiForum = array(); | |
if(mysql_num_rows($result) != 0) | |
{ | |
while($row = mysql_fetch_assoc($result)) | |
{ | |
//display post data | |
$senaraiForum[] = '<tr><th colspan="2">' | |
. $row['topik_subjek'] . '</th></tr>'; | |
} | |
} | |
//fetch the posts from the database | |
$posts_sql = "SELECT | |
forum_komen.komen_topik, | |
forum_komen.komen_kandungan, | |
forum_komen.komen_tarikh, | |
forum_komen.komen_pengepos, | |
forum_komen.tadika_id, | |
forum_komen.tadika_nama | |
FROM | |
forum_komen | |
LEFT JOIN | |
pihaktadika | |
ON | |
forum_komen.post_by = pihaktadika.tadika_id | |
WHERE | |
forum_komen.komen_topik = " . mysql_real_escape_string($_GET['id']); | |
$posts_result = mysql_query($posts_sql); | |
// masuk dalam tatasusunan | |
if(mysql_num_rows($posts_result) != 0) | |
{ | |
while($posts_row = mysql_fetch_assoc($posts_result)) | |
{ | |
$senaraiForum[] = '<tr class="topic-post">' | |
. '<td class="user-post">' . $posts_row['tadika_nama'] . '<br/>' | |
. date('d-m-Y H:i', strtotime($posts_row['komen_tarikh'])) . '</td>' | |
. '<td class="post-content">' . htmlentities(stripslashes($posts_row['komen_kandungan'])) . '</td>' | |
. '</tr>'; | |
// semak ada $_SESSION untuk reply forum | |
if(!$_SESSION['signed_in']) | |
{ | |
$senaraiForum[] = '<tr><td colspan=2>Pengguna perlu ' | |
. '<a href="signin.php">log masuk</a> untuk melayari laman ini, ' | |
. 'atau <a href="signup.php">daftar akaun baru </a>.'; | |
} | |
else | |
{ | |
//show reply box | |
$senaraiForum[] = '<tr><td colspan="2"><h2>Komen :</h2><br />' | |
. '<form method="post" action="reply.php?id=' . $row['topik_id'] . '">' | |
. '<textarea name="reply-content"></textarea><br /><br />' | |
. '<input type="submit" value="Hantar" />' | |
. '</form></td></tr>'; | |
} | |
} | |
} | |
// baru paparkan data | |
if(mysql_num_rows($result) == 0) | |
{ | |
echo 'Topik tidak dapat dipaparkan. Sila cuba lagi !'; | |
} | |
else | |
{ | |
if(mysql_num_rows($posts_result) == 0) | |
{ | |
echo '<table><tr><td>' | |
. 'Paparan topik tidak dibenarkan. Sila cuba lagi !' | |
. '</td></tr></table>'; | |
} | |
else | |
{ // papar data forum | |
$paparData = implode("\n",$senaraiForum); | |
echo '<table>' . $paparData . '</table>'; | |
} | |
} | |
include 'footer.php'; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment