這裏是全碼:需要一個手,像系統
<?php
session_start();
if(!isset($_SESSION["sess_user"])){
header("location:../logout.php");
} else {}
$user=$_SESSION['sess_user'];
?>
<?php
$con=mysql_connect('localhost','root','vertrigo') or die(mysql_error());
mysql_select_db('user_registration') or die("cannot select DB");
$sql=mysql_query("SELECT * FROM `likehand`");
while($likehandle = mysql_fetch_array($sql))
{
$fanname = $likehandle['Userlame'];
$Posid = $likehandle['Post_ID'];
}
?>
<?php
echo "<div style='background-color: #CC98CC'>";
echo "<tr align='center'bgcolor='#f0f0f0'>";
echo"<td><p align='center'><font size='1' color='black'><b>Welcome Back $user </b></a></font></p></td>";
echo "</tr>";
echo "</div>";
echo"<p align='center'><i><b>
<font style='opacity: 100' size='7' color='000000' face='forte'>News</font></b></i></p>";
include("newsdb.php");
if(isset($_POST['submit'])){
if(!empty($_POST['search'])) {
$srhuser=$_POST['search'];
$con=mysql_connect('localhost','root','vertrigo') or die(mysql_error());
mysql_select_db('user_registration') or die("cannot select DB");
$result=mysql_query("SELECT * FROM `news` where submitted_by='".$srhuser."'");}}
else{$result=mysql_query("SELECT * FROM `news`\n"
. " ORDER BY `code` DESC");
}
while($test = mysql_fetch_array($result))
{
$sbmitter = $test['submitted_by'];
$id = $test['code'];
$date = $test['date'];
$body = $test['body'];
$likes = $test['likes'];
$image = $test['url'];
$sql="SELECT * FROM `likehand`";
echo "<div style='background-color: #C0C0C0'>";
echo "<tr align='center'bgcolor='#f0f0f0'>";
echo"<td><i><left><font color='black'> $sbmitter Said:</center></font></i>";
echo"<td><p align='center'><font size='4' color='black'>$body</a></font></p></td>";
echo"<font color='Black'><p align='right'>created <a href='#'>";echo"<font color='blue'>";
echo date('d-m-Y \a\t\ g:i <b>a</b></a>', strtotime($test["date"])); // October 5, 2008 9:34 pm
echo" ";
$userid="$user-$id";
if("$fanname-$Posid" == $userid){echo"<td><p align='Left'><font size='2' color='black'>  $likes like <a href ='unlike.php?code=$id'><font color='black'><input type='button' value='Unlike' name='B3' style='width: 50; height: 20'></a></a></font></p></td>";
}else{ echo"<td><p align='Left'><font size='2' color='black'>  $likes like <a href ='like.php?code=$id'><font color='black'><input type='button' value='like' name='B3' style='width: 50; height: 20'></a></a></font></p></td>";
} if($sbmitter == $user)
{ echo"<td><p align='right'><font size='2' color='black'><a href ='adminpannel/postdel.php?code=$id'><font color='black'><input type='button' value='delete' name='B3' style='width: 50; height: 20'></a></a></font></td>";
echo"<td><font size='2' color='black'><a href ='/adminpannel/postedit.php?code=$id'><font color='black'><input type='button' value='edit' name='B3' style='width: 50; height: 20'></a></a></font></p></td>";
}
}
echo "</div>";
echo "<p></p>";
echo" ";
echo "</tr>";
mysql_close($conn);
?>
我認爲這個問題是在這裏,但不知道它是什麼:
$userid="$user-$id";
if("$fanname-$Posid" == $userid){echo"<td><p align='Left'><font size='2' color='black'>  $likes like <a href ='unlike.php?code=$id'><font color='black'><input type='button' value='Unlike' name='B3' style='width: 50; height: 20'></a></a></font></p></td>";
}else{ echo"<td><p align='Left'><font size='2' color='black'>  $likes like <a href ='like.php?code=$id'><font color='black'><input type='button' value='like' name='B3' style='width: 50; height: 20'></a></a></font></p></td>";
}
我重新檢查了數據庫,並將其似乎它保存了正確的數據,問題是當用戶按下像..喜歡字段增加一和帖子ID以及用戶名被保存,但是當我喜歡多個帖子時,只有一個帖子顯示「不同」按鈕.. 有什麼建議嗎?
請在發佈代碼前介紹問題。這會讓讀者更容易理解這個問題。 –