Sussex_Chris
04-02-2010, 02:10 AM
I have got a simple query that selects an ID from a database:
$idsql = mysql_query("SELECT * FROM ids WHERE sex<4 ORDER BY RAND() LIMIT ".$max."");
My $max limit is set at 30 rows.
And then the num rows check:
if (mysql_num_rows($idsql)<1){echo "Out Of ID's<br />"; exit;}
And this just keeps on returning the following error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in.....
The thing is, when the DB has under 100K rows it is fine, as soon as I start going higher it starts getting this problem. Preferably I would like 1 million+ rows in the table but I can't even get my server to let me pull back 27 random records from a 200K row table.
SQL Structure:
CREATE TABLE `ids` (
`id` bigint(20) NOT NULL,
`sex` tinyint(1) NOT NULL,
`country` varchar(255) NOT NULL,
PRIMARY KEY (`fbid`),
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Any ideas why this error would happen?
Edit: Been doing a bit of research and I it is down to the ORDER BY RAND() query. The problem is, without this when I run multiple instances duplicate rows are returned, is there an alternative way to order this much data my random?
$idsql = mysql_query("SELECT * FROM ids WHERE sex<4 ORDER BY RAND() LIMIT ".$max."");
My $max limit is set at 30 rows.
And then the num rows check:
if (mysql_num_rows($idsql)<1){echo "Out Of ID's<br />"; exit;}
And this just keeps on returning the following error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in.....
The thing is, when the DB has under 100K rows it is fine, as soon as I start going higher it starts getting this problem. Preferably I would like 1 million+ rows in the table but I can't even get my server to let me pull back 27 random records from a 200K row table.
SQL Structure:
CREATE TABLE `ids` (
`id` bigint(20) NOT NULL,
`sex` tinyint(1) NOT NULL,
`country` varchar(255) NOT NULL,
PRIMARY KEY (`fbid`),
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
Any ideas why this error would happen?
Edit: Been doing a bit of research and I it is down to the ORDER BY RAND() query. The problem is, without this when I run multiple instances duplicate rows are returned, is there an alternative way to order this much data my random?