jalaladdin
Active Member
برای مطالب سایتم ،فرم ارسال نظر ساختم حالا چگونه کد بنویسم تا نظراتی که درپایگاه داده ذخیره و شده مورد تائید مدیر سایت هست در قسمت نظرات نشان داده شود
با تشکر
با تشکر
<?php
$con=mysql_connect("localhost","root","")or die(mysql_error());
mysql_select_db("admin", $con);
$result = mysql_query("SELECT * FROM idea");
echo "<table border='1'>
<tr>
<th>ردیف</th>
<th>نام</th>
<th>ایمیل</th>
<th>پیام</th>
<th>تائید</th>
<th>حذف</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo'<p>';
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['email'] . "</td>";
echo "<td>" . $row['message'] . "</td>";
?>
<td align="center" onMouseOut="this.style.backgroundColor = ''" onMouseOver="this.style.backgroundColor = '#e4e4e4'"><a href="?delID=<?php echo $row_rsNews['id']; ?>">تائید</a></td>
<td align="center" onMouseOut="this.style.backgroundColor = ''" onMouseOver="this.style.backgroundColor = '#e4e4e4'" >
<a href="del idea.php?id=<?php echo $row['id']; ?>" onClick="return confirm(' آیا برای حذف مطلب نام( <?php echo $row['id']; ?> ) مطمئن هستید؟ ');">[x]</a></td>
<?php echo "</tr>";
echo'</p>';?>
<?php }
mysql_close($con);
?>
</p>
</div></table>
</body>
</html>
SELECT *
FROM `idea`
WHERE `cid` =3
AND `checked` =1
ORDER BY `id` ASC
SELECT m.*
FROM message m
INNER JOIN idea i ON m.id = i.cid
WHRER m.id = 3 AND i.checked=1
$accept = mysql_query("SELECT idea.name,idea.message,message.text1
FROM idea INNER JOIN message on idea.id=message.id ORDER BY idea.name ");
echo mysql_error();
if(mysql_num_rows($accept)>0)
{
while ($news_i = mysql_fetch_assoc($accept))
{
echo'<p>';
echo '<DIV class=" bg-blue02 t ">'."\n";
echo $news_i['name'];
echo '</DIV>'."\n";
echo '<DIV class=" text ">'."\n";
echo $news_i['message'].'<BR/>'."\n";
echo '</DIV>'."\n";
echo'</p>';
}
}
<?php
$conn = mysql_connect("localhost", "root", "");
if (!$conn) {
echo "Unable to connect to DB: " . mysql_error();
exit;
}
if (!mysql_select_db("test")) {
echo "Unable to select mydbname: " . mysql_error();
exit;
}
/** ********************************************* **/
$id = intval($_POST['id']);
//$id = 2;
$sql = "SELECT * FROM message WHERE id=$id LIMIT 1";
$result = mysql_query($sql);
if (!$result) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}
$row = mysql_fetch_object($result);
?>
<div>
<p><?php echo $row->title; ?></p>
<div><?php echo $row->text; ?></div>
</div>
<?php
/** show comments **/
$sql = "SELECT * FROM idea WHERE cid=$id AND checked=1";
$result = mysql_query($sql);
if (!$result) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
exit;
}
if (mysql_num_rows($result) == 0) {
echo "No comment!";
exit;
}
while ($comment = mysql_fetch_assoc($result)) {
echo "<hr> \n";
echo $comment['text'];
}
mysql_free_result($result);
$accept = mysql_query("SELECT *
FROM idea
$accept = mysql_query("SELECT idea.name,idea.message,message.text1
FROM idea INNER JOIN message on idea.id=message.id ORDER BY idea.name ");
درود بر شما
یه سوال ازتون می پرسم می خوام جوابشو همین الان به خودتون بدین:
اگه هزارتا کامنت توی جدول idea باشه، برنامه باید از کجا بفهمه کدوم کامنت برای کدوم مطلب هست؟!
خب من گفته بودم که یه فیلد دیگه، مثلن به اسم cid یا mid یا... باید اضافه کنید و آیدی مطلبی که کامنت برای اون فرستاده شده رو توش بریزید.
پیوست رو ببینید
شاد باشید
<?PHP
mysql_connect('localhost','root','') or die('Could not connect.');
mysql_select_db('admin') or die('Database does not exist.');
if(isset($_GET['id']) && $_GET['id']!='' && is_numeric($_GET['id']))
{
$news = mysql_query("select * FROM `message` WHERE `id`=' ".intval($_GET['id'])."' LIMIT 1");
echo mysql_error();
if(mysql_num_rows($news)>0)
{
$news_i=mysql_fetch_assoc($news);
}
echo '<DIV class=" bg-blue02 t ">'."\n";
echo $news_i['title'];
echo '</DIV>'."\n";
echo '<DIV class=" text ">'."\n";
echo $news_i['text1'].'<BR/>'."\n";
echo '</DIV>'."\n";
echo'<p><center>';
echo"نظرات";
echo'</center></p>';
echo '<DIV class=" text ">'."\n";
$id = intval($_POST['id']);
$accept = mysql_query("SELECT * FROM idea ");
echo mysql_error();
if(mysql_num_rows($accept)>0)
{
while ($news_i = mysql_fetch_assoc($accept))
{
echo'<p>';
echo '<DIV class=" bg-blue02 t ">'."\n";
echo $news_i['name'];
echo '</DIV>'."\n";
echo '<DIV class=" text ">'."\n";
echo $news_i['comment'].'<BR/>'."\n";
echo '</DIV>'."\n";
echo'</p>';
}
}
if (mysql_num_rows($accept) == 0) {
echo "No comment!";
}
echo'<p><center>';
echo"ارسال نظر";
echo'</center></p>';
printf('
<form action="idea.php" name="contact" method="post" class=" dir "name="signup" id="signup" >
<center><table summary="Demonstration form">
<tbody>
<tr>
<td><label for="name">نام :</label></td>
<td><input name="name" size="35" maxlength="50" type="text"></td>
</tr>
<tr>
<td><label for="email">ایمیل:</label></td>
<td><input name="email" size="35" maxlength="25" type="text"></td>
</tr>
<tr>
<td><label for="comment">پیام:</label></td>
<td><textarea style="width:250px;height:120px" name="comment" type="text"rows="5" cols"100" maxlength="2000"></textarea></td>
</tr>
<tr>
<td> </td>
<td><input name="Submit" value="ارسال" type="submit" class="button" ></td>
<td><input type="reset" value="پاک کردن" name="B2" class="button"> </td>
</tr>
</tbody>
</table></center>
</form>
');
echo '</DIV>'."\n";
}
else
{
$news = mysql_query('SELECT * FROM `message` ORDER BY `id` DESC');
if(mysql_num_rows($news)>0)
{
while ($news_i = mysql_fetch_assoc($news))
{
echo'<p>';
echo '<DIV class=" bg-blue02 t ">'."\n";
echo $news_i['title'];
echo '</DIV>'."\n";
echo '<DIV class=" text ">'."\n";
echo substr($news_i['text1'],0,1000).'<BR/>'."\n";
echo '<a href="'.$filename.'?id='.$news_i['id'].'" class="bg-green03"> ادامه مطلب </A>'."\n";
echo '<a href="'.$filename.'?id='.$news_i['id'].'" class="bg-green03">نظرات</A><BR/>'."\n";
echo '</DIV>'."\n";
echo'</p>';
}
}
}
?>
mysql_query( "SELECT * FROM `comment_tab` WHERE `post_id` = '" . $post_id . "'" );