Итак, я запускаю SQL-запрос через PHP, который возвращает две строки в массиве с двумя столбцами "Suppler"
и "ViewAll"
.
Мне нужно получить значения для каждой строки и проверить view all
это да, поэтому отправьте "Supplier"
идентификаторов в переменную для использования в другом операторе SQL.
Таким образом, соответствующий оператор должен иметь вид IF "View all" = 1
THEN добавить поставщика к переменной $ va, например
IЯ уже пробовал приведенный ниже код, но могу только заставить его вернуть первую строку
protected function getAllInidents($c_id) {
//Getting view all incidents for retilaer
$contact_id = (int) $c_id;
// print_r($contact_id);
try {
//This query may bring back one row or multiple
$q1 = RNCPHP\ROQL::query("SELECT * FROM Retail.RetailerContactRel where Contact = {$contact_id}")->next();
//getting values from returned query
while ($q1r = $q1->next()) {
$ret = $q1r['Retailer'];
$va = $q1r['ViewAllTickets'];
}
//This if statemnet should evaluate the results from above and if matched the $ret id(s) needs to be passed to the ROQL statment , there could be many $ret results if there are more than one result
if ($va != "0") {
$newIncidentArray = array();
//First check if contact has logged any tickets yet if not diplsay message and exit
$roql_result = RNCPHP\ROQL::query("SELECT Incident.ID FROM Incident where Incident.PrimaryContact.Contact=" . $contact_id . " AND Incident.CustomFields.Retail.RetailerDetails is not null")->next();
if (!empty($roql_result)) {
//if user has logged tickets retrieve them and also retrieve any retailer tickets where the user has view all tickets for the retailer set to yes
$roql_result = RNCPHP\ROQL::query(
"SELECT Incident.StatusWithType.Status.LookupName as Status, Incident.ID, Incident.customfields.retail.RetailerDetails.RetailerName, LookupName, Subject, Severity, Incident.PrimaryContact.ParentContact.Emails.EmailList.Address AS CreatedByUser, Incident.CreatedTime AS CreatedTime, Incident.ClosedTime AS ClosedTime
FROM Incident
WHERE incident.customfields.retail.RetailerDetails = {$ret} AND Incident.PrimaryContact.ParentContact.Emails.EmailList.Address is not null
OR Incident.PrimaryContact.Contact = {$contact_id} AND Incident.PrimaryContact.ParentContact.Emails.EmailList.Address is not null"
)->next();
//changing the date format from unix time staff to a readable front end format
while ($inc = $roql_result->next()) {
if ($inc['CreatedTime']) {
$date = $inc['CreatedTime'];
$time = strtotime($date);
$inc['CreatedTime'] = date("m/d/Y", $time);
}
if ($inc['ClosedTime']) {
$date = $inc['ClosedTime'];
$time = strtotime($date);
$inc['ClosedTime'] = date("m/d/Y", $time);
}
$newIncidentArray[] = $inc;
}
//returning list of incidents in an array this is then passed to logic.js
return $newIncidentArray;
} else {
return "You don't have any tickets created.";
}
} else {
$newArray = array();
$newIncidentArray = array();
$a = 0;
$roql_result = RNCPHP\ROQL::query(
"SELECT Incident.ID
FROM Incident
WHERE Incident.PrimaryContact.Contact=" . $contact_id . " AND Incident.CustomFields.Retail.RetailerDetails is not null"
)->next();
if (!empty($roql_result)) {
//do same here
$roql_result = RNCPHP\ROQL::query(
"SELECT Incident.StatusWithType.Status.LookupName as Status, Incident.ID, Incident.customfields.retail.RetailerDetails.RetailerName, LookupName, Subject, Severity, Incident.PrimaryContact.ParentContact.Emails.EmailList.Address AS CreatedByUser, Incident.CreatedTime AS CreatedTime, Incident.ClosedTime AS ClosedTime
FROM Incident
WHERE Incident.PrimaryContact.Contact = {$contact_id} AND Incident.PrimaryContact.ParentContact.Emails.EmailList.Address is not null"
)->next();
while ($inc = $roql_result->next()) {
if ($inc['CreatedTime']) {
$date = $inc['CreatedTime'];
$time = strtotime($date);
$inc['CreatedTime'] = date("m/d/Y", $time);
}
if ($inc['ClosedTime']) {
$date = $inc['ClosedTime'];
$time = strtotime($date);
$inc['ClosedTime'] = date("m/d/Y", $time);
}
$newIncidentArray[] = $inc;
}
return $newIncidentArray;
} else {
return "You don't have any tickets created.";
}
}
} catch (Connect\ConnectAPIErrorBase $e) {
$warnings[] = $e->getMessage();
}
}
Просто возвращает первую строку и не могу добавить, используя. =
SQL будет выглядеть примерно такэто SELECT * FROM table WHERE supplier = (id1,id2)