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.ThanksAustin
On Mon, Apr 11, 2011 at 8:15 AM, Greg Knaddison <greg@growingventuresolutions.com> wrote:
On Sun, Apr 10, 2011 at 8:35 PM, Austin Einter <austin.einter@gmail.com> wrote:You are close, but you need one last piece:
> 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.
>
$query = db_query($query_string, $pieces);
$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);
^^^^^^^^^^^^^^^^^^
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