chitoiu daniel
chitoiu daniel

Reputation: 107

Escape double quotes inside query

I'm scratching my head with this and i can't figure what's wrong

 $result=mysql_query("SELECT * 
                     FROM `offers` 
                     WHERE 
                     (
                         type='$tran' && 
                         imob='$typeimob' &&
                         (
                           'str_replace("_"," ",$zone)'
                            LIKE CONCAT('%',area,'%')
                         )
                     ) 
                     ORDER BY `price` DESC 
                     LIMIT 0, 50;");
    }

This is inside a php. The problem is that I have to escape the double quotes inside str_replace, and i tried str_replace(\"_\",\" \",$zone) but it doesn't work.

Any idea?

Thanks

Upvotes: 0

Views: 713

Answers (1)

frost287
frost287

Reputation: 81

You need to concatenate the output of str_replace() into your string.

    $result=mysql_query(
        "SELECT * 
        FROM `offers` 
        WHERE 
        (
        type='$tran' &&
         imob='$typeimob' &&
         (
            '".str_replace("_"," ",$zone)."' 
            LIKE CONCAT('%',area,'%')
            )
        ) 
        ORDER BY `price` DESC LIMIT 0, 50;");

By the way, if you are using an IDE like Eclipse PDT, these things will be apparent to you right away :)

Upvotes: 0

Related Questions