tags:

views:

34

answers:

1

I am getting this error : ERRNO: 2 TEXT: Division by zero LOCATION: C:\xampp\htdocs\final\classes\customer.php, line 183, at April 2, 2010, 3:49 pm

I have the following function in my class Customer

public static function GetQuotationDetails($string)
    {
        $sql = 'SELECT I.name, I.discounted_price, I.other_name
                FROM item I
                WHERE ( I.name LIKE CONCAT(  '%', :string,  '%' )) ---line 183
                AND T.item_name=:string';
        $parameters = array(':string' => $string);
        DB::GetAll($sql,$parameters);



    }

Then,

$this->results = Customer::GetQuotationDetails('grinder');

and i echo the results by

echo $obj_quotations->results;

Can anyone help me? When i run the sql code and replace :string by 'grinder', it displays the required records.

+4  A: 

The syntax highlighting in your question is a dead give-away. The % signs aren't treated as part of the string. They are actually trying to compute the remainder of dividing two strings.

You need to escape the single-quotes in the SQL statement, thus:

...LIKE CONCAT(  \'%\', :string,  \'%\' ))

Or (my preference) use a double-quoted string for the statement so that the single-quotes aren't treated as special.

Marcelo Cantos
Yes, if a string contains single quotes, it is common practice to delimit the string with double quotes to increase code readability.
Techpriester
Thanks a lot for your help.It worked!
chupinette