views:

68

answers:

1

I have the following code:

function query_tip($title,$desc)
{
    $q1=("SELECT id, company, name FROM abc
            where ('$title' LIKE CONCAT('% ',company,' %') or
                   '$desc' LIKE CONCAT('% ',company,' %') or
                   '$title' LIKE CONCAT('% ',name,' %') or
                   '$desc' LIKE CONCAT('% ',name,' %'))
              AND company != ''
              AND name != ''");
    $r1=mysql_fetch_array($q1);
    $id=$r1['id'];
    return $id_nse;
}

Here, $title is containing data like "my name is anna" and $desc is having data like "I am a programmer at xyz company and I work on the PHP platform."

However, it is giving this error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /bin/whatever on line 2005

but when I run this query on a command prompt or in my database, it runs fine with no error.

Why is this query giving an error when I run it via PHP?

+3  A: 

You are not running your query. You may want to check your query as well (i.e. print it to the screen if it fail or log it to the file). It looks a bit weird.

$q1 = "SELECT id, company, name FROM abc where ('$title' LIKE CONCAT('% ',company,' %') or '$desc' LIKE CONCAT('% ',company,' %') or '$title' LIKE CONCAT('% ',name,' %') or '$desc' LIKE CONCAT('% ',name,' %')) AND company != '' AND name != ''";
$res = mysql_query($q1);
$r1 = mysql_fetch_array($res);
RaYell
ohh my goddddd !!! that's the result of the hurry that i was in to finish this work of mine......kind of embarrassing actually :-) ...but thanks anyways :-)
developer