[support] String conversion

Austin Einter austin.einter at gmail.com
Mon Apr 11 03:13:08 UTC 2011


Thanks Greg.
It was my mistake.

$skill = "SQL, PHP";

As there is a precceding space before PHP, so it was not matching.
Now I need to see how do  I trim the spaces. db_placeholders is really
powerful,,, thanks everybody again.

Best Regards,
Austin



On Mon, Apr 11, 2011 at 8:23 AM, Austin Einter <austin.einter at gmail.com>wrote:

> Thanks Greg. Inching closer. Got partial result.
>
>  $skill = "SQL, PHP";
>
>  $pieces = explode(",", $skill);
>
>  $query_string = '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 ( ' . db_placeholders($pieces,
> 'varchar') . ')))';
>
>  $query = db_query($query_string, $pieces);
>
> This gives records having skill set only SQL.
>
> If I change $skill as below
>
>  $skill = "PHP, SQL";
>
> I get records having PHP skill only.
>
> So it is only taking the first element of array. I wanted it to take all
> the arguements in array.
>
> Thanks
> Austin
>
>
>
>
> On Mon, Apr 11, 2011 at 8:15 AM, Greg Knaddison <
> greg at growingventuresolutions.com> wrote:
>
>> On Sun, Apr 10, 2011 at 8:35 PM, Austin Einter <austin.einter at gmail.com>
>> wrote:
>> > Hi All
>> > On further exploring..
>> >
>> >  $skill = "PHP, TML, HTML";
>> >  $pieces = explode(",", $skill);
>> >
>> > $query_string = '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 ( ' . db_placeholders($pieces,
>> > 'varchar') . ')))';
>> >
>> >  drupal_set_message($query_string);
>> >  $query = db_query($query_string);
>> >
>> >
>> > The output prints as
>> >
>> > 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','%s','%s')))
>> >
>> > But I do not see , pieces[0], pieces[1] and pieces[2] etc in query
>> string.
>> > Is it fine or I am doing something wrong here.
>> >
>>
>> You are close, but you need one last piece:
>>
>> $query_string = '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 ( ' . db_placeholders($pieces,
>> 'varchar') . ')))';
>>
>>  drupal_set_message($query_string);
>>  $query = db_query($query_string, $pieces);
>>                                         ^^^^^^^^^^^^^^^^^^
>>
>> The $pieces as an argument to $db_query should get it done.
>>
>> Also, for debugging sql I love using the Devel module and enabling
>> query logging and printing the query log. It shows the exact query
>> without having to do a drupal_set_message and after any argument
>> substitution takes place.
>>
>> Cheers,
>> Greg
>>
>> --
>> Greg Knaddison | 720-310-5623 | http://growingventuresolutions.com
>> http://masteringdrupal.com - Videos and Tutorials
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.drupal.org/pipermail/support/attachments/20110411/2147de0d/attachment-0001.html 


More information about the support mailing list