我正在努力应该是一个简单的查询,尽管互联网搜索等我仍然无法找到有用的东西。这是我的代码 -
<?php require_once('../Connections/spotting.php');
include_once ("../auth.php");
include_once ("../authconfig.php");
include_once ("../check.php");
$username = $check["uname"];
$query = "SELECT * FROM spotting WHERE uname='$username'";
$result = mysql_query($query) or die ('unable to run R1: ' .mysql_error());
$count = mysql_num_rows($result);
$query2 = "SELECT spots FROM authuser WHERE uname='$username'";
$result2 = mysql_query($query2) or die ('unable to run R2: ' .mysql_error());
$spotval = $result2['spots'];
echo "you have $count Records </p>" ;
if($count==$result2)
{
header( 'Location: http://www.mysite.co.uk/upgrade.php' ) ;
}
else {
echo "You are below your limit $result2";
}
?>
&#13;
有人能指点我吗?
答案 0 :(得分:1)
根据代码,您将第一个查询的总记录与第二个查询的记录进行比较。
你应该做
//OLD code
$result2 = mysql_query($query2) or die ('unable to run R2: ' .mysql_error());
$count1 = mysql_num_rows($result2);
if($count == $count1)
根据您的评论,您应该进行以下更改
if($count == $spotval)
和header already sent
问题。删除echo "you have $count Records </p>" ;
。因为如果要重定向页面,则不需要这样做。
答案 1 :(得分:1)
如果您只想重定向到其他网页,请尝试以下方法:echo "<script>window.location.assign('goToThisPage.html');</script>"
答案 2 :(得分:1)
尝试获取第二个查询的行数并进行检查
<?php require_once('../Connections/spotting.php');
include_once ("../auth.php");
include_once ("../authconfig.php");
include_once ("../check.php");
$username = $check["uname"];
$query = "SELECT * FROM spotting WHERE uname='$username'";
$result = mysql_query($query) or die ('unable to run R1: ' .mysql_error());
$count = mysql_num_rows($result);
$query2 = "SELECT spots FROM authuser WHERE uname='$username'";
$result2 = mysql_query($query2) or die ('unable to run R2: '
.mysql_error());
$spotval = $result2['spots'];
$count2 = mysql_num_rows($result2);
echo "you have $count Records </p>" ;
if($count==$count2)
{
header( 'Location: http://www.mysite.co.uk/upgrade.php' ) ;
}
else {
echo "You are below your limit $result2";
}
?>