Forum Moderators: coopster

Message Too Old, No Replies

Multi Query and Display issue in PHP

Stuck!

         

anawaz

3:34 pm on Oct 20, 2009 (gmt 0)

10+ Year Member



Hi Folks,

I have a bit of a problem, and I know it's simple, but today I just can't seem to get around it, so I need some help!

Here is what I am trying to do with MySQL and PHP:

I'm running one query to get a certain number of fields returned. Here is the code in php:


$User_Services = mysql_query("SELECT DISTINCT `service_id` FROM `user_service_instance` WHERE `user_id` = '"$USERID"' ") or die(mysql_error());

Now, this can give me multiple results, and what I want to do is use each of this results in ONE more query to get what I'm after, for instance:


$GRPS = mysql_query("SELECT DISTINCT `group` from `services_and_groups` WHERE `service_id` != 'RESULT 1 FROM ABOVE` AND `service_id` != 'RESULT 2 FROM ABOVE'")... and so on so forth;

So, irrespective of how many results my first query gives, I want to be able to use all of those in one query. Is there any way i can append them to a variable with commas and then explode them and reuse them in the next query?

Thanks folks!

kamperzoid

8:11 pm on Oct 20, 2009 (gmt 0)

10+ Year Member



$query = "";
while ($results from first query) {
$query .= " `service_id` != 'RESULT 1 FROM ABOVE` AND";
}

$query = substr($query,0,(strlen($query)-3));

and you just put $query behind your second query.

i hope this can help you

anawaz

10:10 pm on Oct 21, 2009 (gmt 0)

10+ Year Member



Well, it turns out my logic was wrong, but this did help in resolving it. Thanks kamperzoid.