user3307827
user3307827

Reputation: 556

SQL_CALC_FOUND_ROWS not working sometimes

$query->select('SQL_CALC_FOUND_ROWS i.title,i.fulltext,i.shorttext');
        $query->from('#__items as i');
$query->where('i.shorttext LIKE "%'.$word.'%");

with this condition everything is right and count of rows is real...for example if it return 21 items...it is real...(the real returned result is 21)

but in this code:

 $query->select('SQL_CALC_FOUND_ROWS i.title,i.fulltext,i.shorttext');
            $query->from('#__items as i');
$query->where('i.shorttext LIKE "%'.$word.'%" 
            OR i.fulltext LIKE "%'.$word.'%" 
            OR i.title LIKE "%'.$word.'%"');

The code return count of rows to me 63! (3 times bigger the real one.)

of course both of them print real times (not dublicate).

what's the wrong? tnx


I changed to this (added brackets around the three or conditions) and the problem solved.

 $query->select('SQL_CALC_FOUND_ROWS i.title,i.fulltext,i.shorttext');
            $query->from('#__items as i');
$query->where('(i.shorttext LIKE "%'.$word.'%" 
            OR i.fulltext LIKE "%'.$word.'%" 
            OR i.title LIKE "%'.$word.'%")');

Upvotes: 1

Views: 574

Answers (1)

Ulrich Thomas Gabor
Ulrich Thomas Gabor

Reputation: 6654

The code returns 63, because your query returns 63 rows (or you changed the variable afterwards in PHP).

It's either a correct result or you extracted the number wrong. There's no magic from MySQL at this point.

Upvotes: 0

Related Questions