[support] String conversion

Austin Einter austin.einter at gmail.com
Mon Apr 11 02:00:56 UTC 2011


Anth
Thanks for help.

I tried this option, still get '\' warning.

$skill = "PHP, TML, HTML";
 $pieces = explode(",", $skill);
 $in_string = "'" . implode("','", $pieces) . "'";

$query = db_query("SELECT name, email, phone, yrsofexp FROM {resubmt_table}
  WHERE resubmt_table.uid IN (SELECT DISTINCT uid FROM
{resubmt_users_skills}
  WHERE resubmt_users_skills.skillid IN(SELECT skillid FROM {resubmt_skills}

  WHERE resubmt_skills.skillname IN (%s)))", $in_string);


I get the warning

user warning: You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near
'\'PHP\',\' TML\',\' HTML\')))' at line 4 query: SELECT name, email, phone,
yrsofexp FROM resubmt_table WHERE resubmt_table.uid IN (SELECT DISTINCT uid
FROM resubmt_users_skills WHERE resubmt_users_skills.skillid IN(SELECT
skillid FROM resubmt_skills WHERE resubmt_skills.skillname IN (\'PHP\',\'
TML\',\' HTML\'))) in
C:\MyWeb6.20\wamp\www\livejobs1\sites\default\modules\resume_search\resume_search.module
on line 126.


Thanks
Austin
On Mon, Apr 11, 2011 at 7:00 AM, Anth <malkouna at yahoo.com.au> wrote:

> Sometimes you can't control what you're getting for your IN statement...
>
> Try something like:
>
> $string = "PHP,HTML,SQL";
> $pieces = explode(",", $string);
> $in_string = "'" . implode("','", $pieces) . "'";
>
> On 6:59 AM, nan wich wrote:
>
>  In Drupal code, you should *never* find a query with %s that is not
> surrounded by quotes. To do what you are looking for check the
> db_placeholders function in the API docs.
>
>
> *Nancy*
>
>
>
> Injustice anywhere is a threat to justice everywhere. -- Dr. Martin L.
> King, Jr.
>
>
>  ------------------------------
> *From:* Austin Einter <austin.einter at gmail.com>
> *To:* support at drupal.org
> *Sent:* Sun, April 10, 2011 8:23:57 PM
> *Subject:* [support] String conversion
>
> Hi
> I have a below string.
> *PHP, HTML, SQL*
> Want to convert it to
> *'PHP', 'HTML', 'SQL'*
>
> I tried to write a function to do it as below. If I print the function
> output it prints properly.
> If same function output I use for SQL query as below I get warning.
>
> Query:    SELECT skillid FROM {resubmt_skills}   WHERE
> resubmt_skills.skillname IN (%s)", $fSkill
> Warning:   SELECT skillid FROM resubmt_skills WHERE
> resubmt_skills.skillname IN (\'ITI\',\' PHP\'))) in
> C:\MyWeb6.20\wamp\www\livejobs1\sites\default\modules\resume_search\resume_search.module
> on line 140.
>
> Looks it has extra forward slashes. How can I overcome this.
>
> Thanks
> Austin
>
>
>
>
>
> --
> [ Drupal support list | http://lists.drupal.org/ ]
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20110411/c88afbbb/attachment.html 


More information about the support mailing list