Jump to content

SQL query


Chill_user

Recommended Posts

Hello, here is my code:

$result = Db::getInstance()->getRow('
                        SELECT `id_category`
                        FROM `'._DB_PREFIX_.'category_group` 
                        WHERE `id_category` = '.$id_category'
                        AND `id_group` = '.$id_customer'
                        ');

But I have an error! If I delete 'AND' statement line, all is working (valid code)

Tried to send this request with "Advanced Parameters -> Database -> SQL" and all is working well! (of course I changed $id_category and $id_customer for numbers)

What is the problem with code?

Edited by Amantha Bill (see edit history)
Link to comment
Share on other sites

10 minutes ago, Nishith said:

Hi..

use this code may be help not tested i hope its wrok

 


$query = 'SELECT id_category FROM `'._DB_PREFIX_.'category_group` WHERE `id_category` = '.$id_category.' AND `id_group` = '.$id_customer;
$result = Db::getInstance()->getRow($query);


Thanks

Thanks 4 quick reply!

Yes, it's working! But I didn't understand what was incorrect in my code...

Link to comment
Share on other sites

Hi,

Kindly refer to line below for the error (& Differences).

Your Code:

SELECT `id_category`
FROM `'._DB_PREFIX_.'category_group` 
WHERE `id_category` = '.$id_category'
AND `id_group` = '.$id_customer'

 

It should be
 

SELECT `id_category`
FROM `'._DB_PREFIX_.'category_group` 
WHERE `id_category` = '.$id_category.'
AND `id_group` = '.$id_customer.'

 

(Dot after the $id_category & $id_customer)

 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...