简体   繁体   中英

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

$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

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.

Then use:

($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. Therefore, you are creating a never ending loop!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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