/    Sign up×
Community /Pin to ProfileBookmark

I am not sure if this is a MySql or php problem.

Hi

I am not sure if this is a MySql or php problem.

How do I check if a mysql table is empty?

I have used this code:

[CODE]
$Exist = “SELECT * FROM log WHERE CName=’$CName’ AND League=’$Liga AND Day=’$Days'”;
$result = mysql_query($Exist);
$num=mysql_numrows($result);
[/CODE]

to search the table for the content but if the table is empty with no data rows in it I get the following error.

Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in C:XitamiwebpagesWPCricketData AdminAddresult.php on line 266

Line 266 is $num=mysql_numrows($result);

How do I prevent this error?

Pleas help.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@pcthugSep 13.2006 — The mysql_numrows function is deprecated, use the mysql_num_rows function instead. Also make use of the mysql_errno and mysql_error functions.
[code=php]
$Exist = "SELECT * FROM log WHERE CName='$CName' AND League='$Liga AND Day='$Days'";
$result = mysql_query($Exist) or die(mysql_errno() . ": " . mysql_error() . "n");
$num = @mysql_num_rows($result);
[/code]
Copy linkTweet thisAlerts:
@bokehSep 13.2006 — The mysql_numrows function is deprecated, use the mysql_num_rows function instead. Also make use of the mysql_errno and mysql_error functions.
[code=php]
$Exist = "SELECT * FROM log WHERE CName='$CName' AND League='$Liga AND Day='$Days'";
$result = mysql_query($Exist);
$num = @mysql_num_rows($result) or die(mysql_errno() . ": " . mysql_error() . "n");
[/code]
[/QUOTE]
You should have the die statement on the query line.[code=php]$result = mysql_query($query) or die('etc');[/code]
Copy linkTweet thisAlerts:
@pcthugSep 13.2006 — Careless mistake...
×

Success!

Help @gogelpot 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.6,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...