/    Sign up×
Community /Pin to ProfileBookmark

count matches php/mysql with big numbers.

Hi,

I have a mysql table with about 400,000 rows and sevral coulums. If I search using php for “a”, the expected number of matches is above 260,000 and I get a “Warning: mysql_query() [function.mysql-query]: Unable to save result set”. I guess it is too much. However, I just would like to count the matches, not display them… Is there a way to count my matches anyway ?

thanks for any help !

[code=php]$data = mysql_query(“SELECT * FROM tab WHERE upper($field) LIKE’%$query%'”);
$anymatches=mysql_num_rows($data); [/code]

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@MrCoderJul 25.2007 — Don't "select *" if you don't need to return any data.
Copy linkTweet thisAlerts:
@patimagesauthorJul 25.2007 — thanks for the quick reply but ...??? How should I count the matches then ? could you post a little exemple ?

thanks !
Copy linkTweet thisAlerts:
@asavinOct 01.2007 — Hi,

I have a mysql table with about 400,000 rows and sevral coulums. If I search using php for "a", the expected number of matches is above 260,000 and I get a "Warning: mysql_query() [function.mysql-query]: Unable to save result set". I guess it is too much. However, I just would like to count the matches, not display them... Is there a way to count my matches anyway ?

thanks for any help !
[code=php]$data = mysql_query("SELECT * FROM tab WHERE upper($field) LIKE'%$query%'");
$anymatches=mysql_num_rows($data); [/code]
[/QUOTE]

Did you try :
[code=php]$data = mysql_query("SELECT COUNT(*) FROM tab WHERE upper($field) LIKE'%$query%'");
$anymatches=mysql_fetch_rows($data);
echo $anymatches[0];
[/code]
×

Success!

Help @patimages spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...