請教一個無重新整理更換圖片的問題

來源:互聯網
上載者:User
我是正做的一個仿美麗說的 jQuery+Ajax+PHP實現“喜歡”評級 功能,現在已經做到了點擊圖片“喜歡”的數量發生改變。

當點擊彩色圖片時,圖片變成另一張灰色的,數量顯示為增1。
當點擊灰色圖片時,數量減1,同時圖片變成彩色的。

現在已經實現了大部分功能,只有圖片的切換沒有實現,希望有高手能協助解決這個問題。

現貼上代碼。

index.php頁代碼:

jQuery+Ajax+PHP實現“喜歡”評級







include_once("connect.php");
$sql = mysql_query("select * from pic");
while($row=mysql_fetch_array($sql)){
$pic_id = $row['id'];
$pic_name = $row['pic_name'];
$pic_url = $row['pic_url'];
$love = $row['love'];
$qqqwww = 2;
?>

">








love.php頁面代碼:
include_once("connect.php");

$ip = get_client_ip();
$id = $_POST['id'];
if(!isset($id) || empty($id)) exit;

$ip_sql=mysql_query("select ip from pic_ip where pic_id='$id' and ip='$ip'");
$count=mysql_num_rows($ip_sql);
if($count==0){
$sql = "update pic set love=love+1 where id='$id'";
mysql_query( $sql);
$sql_in = "insert into pic_ip (pic_id,ip) values ('$id','$ip')";
mysql_query( $sql_in);
$result = mysql_query("select love from pic where id='$id'");
$row = mysql_fetch_array($result);
$love = $row['love'];
echo $love;
}else{
//echo "喜歡過了";

$sql = "update pic set love=love-1 where id='$id'";
mysql_query( $sql);

//$sql_in = "insert into pic_ip (pic_id,ip) values ('$id','$ip')";
//mysql_query( $sql_in);

$sql_in = "delete from pic_ip where ip='$ip'";
mysql_query($sql_in);

$result = mysql_query("select love from pic where id='$id'");
$row = mysql_fetch_array($result);
$love = $row['love'];
echo $love;
}

//擷取使用者真實IP
function get_client_ip() {
if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
$ip = getenv("HTTP_CLIENT_IP");
else
if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))
$ip = getenv("HTTP_X_FORWARDED_FOR");
else
if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
$ip = getenv("REMOTE_ADDR");
else
if (isset ($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
$ip = $_SERVER['REMOTE_ADDR'];
else
$ip = "unknown";
return ($ip);
}
?>


connect.php代 碼:

$host="localhost";
$db_user="root";
$db_pass="root";
$db_name="50000";
$timezone="Asia/Shanghai";

$link=mysql_connect($host,$db_user,$db_pass);
mysql_select_db($db_name,$link);
mysql_query("SET names UTF8");
?


回複討論(解決方案)

現在數量可以無重新整理變換了,要求是點擊的圖片也無重新整理切換。請高手協助解決,也可以私下聯絡我QQ 792785733 ,改好後有酬勞。

原理一樣,給img標籤換個src而已

問題已解決,不要回貼了,多謝回覆

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.