เวลาที่เข้าไปตอบของแต่ละโพสต์มันจะเอาคอมเม้นของทุกโพสต์มาแสดงหมดเลย ไม่รู้ว่าเขียนโค้ดผิดตรงไหน อยากให้มันแสดงเฉพาะของใครของมันอ่ะ...^^
*********หน้า pos11t**********
<? session_start();?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="chack_post1.php">
<? include('../post1/chack_post1.php');?>
<table width="233" height="72" border="0">
<tr>
<td><label>
<textarea name="post" id="post" cols="60" rows="3"></textarea>
</label></td>
</tr>
<tr>
<td><label>
<div align="right">
<input type="submit" name="pos" id="pos" value="post" />
</div>
</label></td>
</tr>
</table>
<p> </p>
<?
include('../member/include.php');
$sid = $_SESSION['sid'] ;
mysql_query("SET NAMES TIS620");
$sql = "select * from tbl_post p,tbl_member m where p.member_id=m.member_id and p.member_id= '$sid'";
$query = mysql_query($sql);
while($result = mysql_fetch_array($query)){
$_SESSION['pid'] = $result["post_id"] ;
?>
<table width="459" border="0">
<tr>
<td width="27" valign="top"><?
if($pic==""){
echo "<img src='../image/none.gif' width='40' height='40'>";
}else{
echo "<img src='../image/".$result["member_pic"]."' width='40' height='40'>";
}?> </td>
<br>
<br>
<td width="320" valign="top" align="left"><p>
<a href="../profile/pro_file.php">
<?=$result["member_username"];?></a> <?=$result["post_date"];?>
<?=$result["post_time"];?>
</p>
<p><br>
<a href="../post1/showps.php? <?=$_SESSION['pid'] ?>" >
<?=$result["post_massage"];?></a>
</p>
</table>
<? } ?>
</form>
</body>
</html>
*********หน้า chack_post1**********
<? session_start();?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?
$pid = $_SESSION['pid'];
?>
<? //post
if($_POST['pos']=="post"){
$pmess = $_POST['post'];
$pdate = date('d / m / Y');
$ptime = date('h:m:s');
include('../member/include.php');
$sid = $_SESSION['sid'] ;
$sqlp = "insert into tbl_post";
$sqlp .= "(post_id,member_id,post_massage,post_date,post_time) values (NULL,'$sid','$pmess','$pdate','$ptime')";
$queryp = mysql_query($sqlp);
echo "<meta http-equiv='refresh' content='0;url=../profile/pro_file.php'/>";
//ment
}else if($_POST['pos']=="ment"){
$cmess = $_POST['comment'];
$cdate = date('d / m / Y');
$ctime = date('h:m:s');
include('../member/include.php');
$sid = $_SESSION['sid'] ;
$sqlm = "insert into tbl_comment ";
$sqlm .="(comment_id,comment_massage,comment_date,comment_time,post_id,member_id) values (NULL,'$cmess','$cdate','$ctime','$pid','$sid')";
$querym = mysql_query($sqlm) or die(mysql_error());
echo "<meta http-equiv='refresh' content='0;url=../post1/showps.php'/>";
}
?>
</body>
</html>
*********หน้า showps**********
<? session_start(); $pid = $_SESSION['pid']; ?>
<form id="form1" name="form1" method="post" action="chack_post1.php">
<div align="center"><br />
<label><br />
</label>
<?
include('../post1/chack_post1.php');
print $pid;
?>
<p> </p>
<?
include('../member/include.php');
$sid = $_SESSION['sid'] ;
mysql_query("SET NAMES TIS620");
$sql = "select * from tbl_post p,tbl_member m where p.member_id = m.member_id and p.post_id='$pid'";
$query = mysql_query($sql);
$result = mysql_fetch_array($query)
?>
<table width="459" border="0">
<tr>
<td width="27" valign="top"><?
if($pic==""){
echo "<img src='../image/none.gif' width='40' height='40'>";
}else{
echo "<img src='../image/".$result["member_pic"]."' width='40' height='40'>";
}?> </td>
<br>
<br>
<td width="320" valign="top" align="left"><p>
<a href="../member/pro_file.php">
<?=$result["member_username"];?></a> <?=$result["post_date"];?>
<?=$result["post_time"];?>
</p>
<p><br>
<?=$result["post_massage"];?>
</p>
<hr>
<input type="hidden" name="id" value="<?=$_SESSION['pid'];?>">
<?
$sqlc = "select * from tbl_comment c , tbl_member m ,tbl_post p where m.member_id = c.member_id and p.post_id = '$pid';";
$queryc = mysql_query($sqlc);
while($resultc = mysql_fetch_array($queryc)){
$_SESSION['id']=$resultc["post_id"];
if($resultc['member_pic']==""){
echo "<br><img src='../image/none.gif' width='40' height='40'>".$resultc['member_username']."";
echo "<br>".$resultc['comment_massage'];
}else{
echo "<br><img src='../image/".$resultc['member_pic']."' width='50' height='50'>".$resultc['member_username']."".$resultc['comment_date'].$resultc['comment_time'];
echo "<br>".$resultc['comment_massage'];
}
}
?> </td>
<td width="98" valign="bottom" align="left"> </td>
</tr>
<tr>
<td> </td>
<td colspan="2" valign="top"><label>
<textarea name="comment" id="comment" cols="40" rows="2"></textarea>
<input type="submit" name="pos" id="pos" value="ment" />
</label></td>
</tr>
</table>
</div>
</form>Tag : PHP, HTML/CSS
Date :
2012-02-23 15:48:31
By :
***a***
View :
991
Reply :
1
// tb_post เก็บ รายการ post
// tb_comment เก็บรายการตอบ พร้อม id ของ tb_post
เวลาแสดง comment ของ รายการ post
select แบบนี้ครับ
Code (PHP)
$id_post = "???";
$sql = mysql_query("select * form tb_comment where tb_post = $id_post");
ประวัติการแก้ไข 2012-02-23 15:58:59
Date :
2012-02-23 15:58:26
By :
mangkunzo
Load balance : Server 04