I have the following code which performs a sql select with a where condition involving an array.
I want subsequent queries (within the same code) to be performed using each unique value of the array
Here are the specifics:
This initial query begins the process by creating an array from which the following queries gets their conditional values.
$SQL = "SELECT clientID, servicearea FROM servicesrendered where servicearea like ' oil change%' group by clientID";
$r = mysql_query($SQL);
while ($row = mysql_fetch_array($r, MYSQL_ASSOC)) {
$clientID=$row['clientID'];
$clients[] = "$clientID";
//$array=array($client,"");
}
foreach($clients as $client) {
$clientID = $client[0];
//$array = array("$client", "");
$list = "'". implode("','", $clients) ."'";
echo "$list";
$get_swork = "SELECT servicearea, date, customerid, clientID FROM servicesrendered WHERE servicearea=' Oil Change ' and clientID IN ($list) order by id ASC limit 1";//limit 1 means the last entered
$get_swork_res = mysql_query($get_swork);
if (mysql_num_rows($get_swork_res) > 0)
{
while ( $swork_info = mysql_fetch_array($get_swork_res))
{
$servicearea = $swork_info['servicearea'];
$date = $swork_info['date'];
$customerid = $swork_info['customerid'];
$clientID = $swork_info['clientID'];
}
}
In the $get_swork statement, the where condition produces the following:
WHERE servicearea=' Oil Change ' and clientID IN ('0927HD','3232','342DF','4FCDS','5437DC','543GD1','5455FV','54FD43','6736HD','87JFJ','DG9642','GDS34','RFFD43','TF42DC')
Now I have two subsequent queries that relies on variables from the preceding query, here are those queries
Denoted as Q1
$get_swork3 = "select * from ajax_client where customerid='$customerid'";//here we are pulling cell and email information from ajax client using the customer id from get_swork2. clientid is not recorded in ajax_client, so this statement is search by customer id
$get_swork3_res = mysql_query($get_swork3);
if (mysql_num_rows($get_swork3_res) > 0)
{
while ( $swork3_info = mysql_fetch_array($get_swork3_res))
{
$email =$swork3_info['email'];
}
}
Denoted as Q2
$get_swork2 = "select * from additional_cars where clientID='$clientID'";// order by id desc limit 1";
$get_swork2_res = mysql_query($get_swork2);
if (mysql_num_rows($get_swork2_res) > 0)
{
while ( $swork2_info = mysql_fetch_array($get_swork2_res))
{
$firstname = $swork2_info['firstname'];
$lastname = $swork2_info['lastname'];
$customerid = $swork2_info['customerid'];
$dhtmlgoodies_category = $swork2_info['dhtmlgoodies_category'];
$dhtmlgoodies_subcategory = $swork2_info['dhtmlgoodies_subcategory'];
$caryear = $swork2_info['caryear'];
} // close foreach
My current task is to perform Q1 and Q2 with each unique array value in the initial query written at the top
Currently, Q1 performs this
select * from ajax_client where customerid='Bs6444'
and stops. I would like to select using the where condition of "customerid" of all associated ids generated in the array.
i.e: the values of array is ('0927HD','3232','342DF','4FCDS','5437DC' ect..), my initial query makes available a variable called $customerid='Bs6444' which is associated with $clientID='0927HD' (the same should happen with all values of the array). And thus,the same for both Q1 and Q2 above.
Is this doable? I know this may be way out of the stratosphere, but I hope there are some thoughts on this.
Any thoughts is very appreciated!
Mossa