Results 1 to 4 of 4

Thread: MySQL Query

  1. #1
    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);

  2. #2
    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.. 
    Regards,

    G
    PutFile.io — Disrupting traditional file hosting.
    █ Signup Early and enjoy Unlimited space/bandwidth for your files hosting, Forever!
    █ No Ads.
    █ No Countdowns.

  3. #3
    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.

  4. #4
    Join Date
    Sep 2002
    Location
    Top Secret
    Posts
    14,135
    The best way to do this, honestly is to let the code do this itself
    Code:
    $result=mysql_query($query) or die(mysql_error());
    will do this

    Code:
    $result = mysql_query("SELECT thepiece FROM writings WHERE ".$category." like ".$searchterm."", $con);
    Firstly, try dropping the $con here. This will help out. What you should be doing is quite simple:

    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
    usually, there's something in there that stops what you need from going through. For example,maybe a mis assigned variable , or, you mistyped something, or hey, maybe you just forgot something
    Tom Whiting, WHMCS Guru extraordinaire
    Linux problems? WHMCS Problems? Give me a shout
    Check out my WHMCS Addons

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •