简体   繁体   English

Mysql_num_rows()问题

[英]Mysql_num_rows() issues

i have written the query below to check if record in the database record matches the condition below. 我已经在下面编写了查询,以检查数据库记录中的记录是否符合以下条件。 I'm sure there's arow that matches this condition, but the problem is that any set of combination returns the "Record Exists" line 我确定会有一个符合此条件的长号,但是问题是任何一组组合都返回“ Record Exists”行

$query = mysql_query("SELECT * FROM         result_upload
WHERE course_code = '$course_code'
WHERE session = $session'
WHERE semester_name = $semester_           name'
WHERE level = $level'") or die
 (mysql_error());

$duplicates = mysql_num_rows($query);
if ($duplicates = 1) 
{
 echo "Record Exists";
}       else
{
echo "No Record";
}

Thanks in advance. 提前致谢。

Try using $duplicates == 1 尝试使用$duplicates == 1

This is the comparison operator rather than assignment. 这是比较运算符,而不是赋值。

您将相等符号(=)两次用于比较(a == b),一次用于赋值(a = b)。

if ($duplicates == 1) {
....
//OR
if ($duplicates > 0) {
.....
if ($duplicates = 1) 

代替这个..写

if ($duplicates == 1) 

First of all you are having more than one WHERE clause in you query, you may replace all the WHERE statements after the initial WHERE with AND. 首先,查询中有多个WHERE子句,可以将初始WHERE之后的所有WHERE语句替换为AND。

Then use: 然后使用:

($duplictes == 1) ($ duplictes == 1)

Hope this helps!? 希望这可以帮助!?

You should use: 您应该使用:

1) only one WHERE clause with AND operator
2) if($duplicates >=1)

Use the double equal (==) sign. 使用双等号(==)。 This is the comparator, which compares two items. 这是比较器,它比较两个项目。 When you use only one equals sign (=) you are setting the variable. 当仅使用一个等号(=)时,将设置变量。 What you need to do is: 您需要做的是:

if ($duplicates == 1) 

instead of 代替

if ($duplicates = 1) 

What you are doing in the later is actually setting $duplicates to one, which will always evaluate to true. 稍后您要做的实际上是将$ duplicates设置为1,它将始终为true。 Therefore, you are creating a never ending loop! 因此,您正在创建一个永无止境的循环!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM