Results 1 to 4 of 4
Thread: MySQL Query
-
10-12-2006, 04:18 PM #1Junior Guru Wannabe
- Join Date
- Oct 2006
- Posts
- 31
MySQL Query
Could anyone be so kind and tell me if there is anything wrong with this line of code. When I put $result as an arugment in mysql_num_rows() I get the following error "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result".
Any help would be lovely.
Code:$result = mysql_query("SELECT thepiece FROM writings WHERE ".$category." like ".$searchterm."", $con);
-
10-12-2006, 04:39 PM #2Living the dream
- Join Date
- May 2005
- Location
- Planet Earth
- Posts
- 813
Hi,
usually it's because an error happened and mysql_query() didn't return an handle.
You can try:
PHP Code:$result = mysql_query("SELECT thepiece FROM writings WHERE ".$category." like ".$searchterm."", $con);
if (!result) {
print mysql_error();
exit;
}
//mysql_num_rows()..
// and the rest of your code..
G█ PutFile.io — Disrupting traditional file hosting.
█ Signup Early and enjoy Unlimited space/bandwidth for your files hosting, Forever!
█ No Ads.
█ No Countdowns.
-
10-12-2006, 04:59 PM #3Junior Guru Wannabe
- Join Date
- Oct 2006
- Posts
- 31
I figured it out. Thanks for the tip!
Last edited by lilnomad; 10-12-2006 at 05:05 PM.
-
10-12-2006, 05:19 PM #4
The best way to do this, honestly is to let the code do this itself
Code:$result=mysql_query($query) or die(mysql_error());
Code:$result = mysql_query("SELECT thepiece FROM writings WHERE ".$category." like ".$searchterm."", $con);
Establish the connection at the beginning of the page load
Close the connection at the end of the page load
No need to use $con, and it could very possibly be causing problems.
If nothing else, take a look at the raw query.
Code:print $query
Tom Whiting, WHMCS Guru extraordinaire
Linux problems? WHMCS Problems? Give me a shout
Check out my WHMCS Addons