我無法重定向計數命中後13重定向當條件滿足
我有圖像的一堆,用戶可以點擊添加到他們的名單在數據庫中,當他們點擊,一點擊js腳本觸發並觸發updatelist.php。
這部分工作正常,在updatelist.php內我需要它插入,然後檢查表,看它是否達到了13的計數,如果是的話,它需要重定向到一個新的頁面。
插入工作正常,但它沒有重定向。下面是我的updatelist.php代碼
<?php
include('connect.php');
session_start();
$username=$_SESSION['username'];
$image = $_GET['image'];
$query = mysql_query("SELECT * FROM tbl_movies cross join tbl_users WHERE image_on = '$image' and username = '$username'");
while ($row = mysql_fetch_assoc($query))
{
$movieid = $row['id'];
$userid = $row['UserID'];
}
$query2 = mysql_query("select * from tbl_movies cross join tbl_users where image_off = '$image' and username = '$username'");
while ($row2 = mysql_fetch_assoc($query2))
{
$mid = $row2['id'];
$uid = $row2['UserID'];
}
$numrows = mysql_num_rows($query);
$numrowz = mysql_num_rows($query2);
if ($numrows!=0)
{
$queryInsert = mysql_query("insert into tbl_user_lists (userid_fk,movie_id_fk) values ('$userid','$movieid')");
$query5=mysql_query("select l.* from tbl_user_lists as l join tbl_users on l.userid_fk=tbl_users.UserID where username='$username'");
$updatecount = mysql_num_rows($query5);
if ($updatecount == 13)
{
header('Location: http://localhost/main.php');
}
}
else if ($numrowz!=0)
{
$queryUpdate = mysql_query("delete from tbl_user_lists where userid_fk = '$uid' and movie_id_fk = '$mid'");
}
?>
下面是調用上面的PHP頁面
<script>
$(function(){
$('.img-swap').live('click', function() {
var _src = $(this).attr('src');
if (-1 == _src.indexOf('_on')) {
$(this).attr('src',_src.replace('_off','_on')).removeClass('off');
} else {
$(this).attr('src',_src.replace('_on','_off')).addClass('on');
}
// Update server
$.get('updatelist.php?image='+escape($(this).attr('src')));
$(this).toggleClass("on");
});
});
</script>
請修復您的職位(代碼高亮)。 – 2011-04-09 18:56:53
「觸發updatelist.php」是什麼意思?你是通過AJAX調用並檢查響應嗎?或者你通過javascript將用戶重定向到updatelist.php? – 2011-04-09 20:07:19
它是一個jQuery腳本,在用戶點擊圖像時在主頁上調用,jquery獲取圖像的名稱並將其發送到updatelist.php以更新db中的表格 – 2011-04-09 20:58:06