[英]prepared mysql statements and arrays
Solved the problem earlier today. 今天早些时候解决了这个问题。 In the 2nd line of code global $db,$tags
; 在代码的第二行中, global $db,$tags
; was overwriting if($this->has_lead_type_selected($person['ID'],$tags))
which caused the global $tags to overwrite $tags at the lower portion of code. 被覆盖if($this->has_lead_type_selected($person['ID'],$tags))
导致全局$ tags覆盖了代码下部的$ tags。 So the global var was empty because it was before the actual $tags var was given a function. 所以全局变量是空的,因为它是在给实际的$ tags var函数之前。
When an HTML form is submitted to our REST API it sends data called 'lead_type' which are simply tags to identify the lead being sent. 当将HTML表单提交到我们的REST API时,它将发送称为“ lead_type”的数据,这些数据只是用于标识要发送的销售线索的标签。
User select these tags from a tag cloud. 用户从标签云中选择这些标签。 If a form is submitted to the API with one of these tags (lead_type) and any of our users profiles match those tags (they selected in their tag cloud). 如果使用这些标签之一(lead_type)将表单提交给API,并且我们的任何用户个人资料都与这些标签匹配(它们在标签云中选择)。 The user is sent a SMS to notify them. 向用户发送一条SMS通知他们。
Everything posts to the database tables, the API works but everyone of the users still gets a SMS even if they don't have matching tags. 一切都发布到数据库表中,该API可以正常工作,但是即使没有匹配的标签,每个用户仍然可以收到SMS。 If I comment out the line (i'll show the rest of the code below) an SMS is sent to everyone. 如果我注释掉该行(我将在下面显示其余代码),则会向所有人发送一条SMS。 If I leave it uncommented no SMS is sent to anyone. 如果我不加注释,则不会将SMS发送给任何人。
if($this->has_lead_type_selected($person['ID'],$tags))
Here is how the code flows. 这是代码的流向。
}
private function has_lead_type_selected($user_id,$tags){
global $db,$tags;
$lead_types = explode(',',$tags);
$user_lead_types = $db
->where('user_id',$user_id)
->where('lead_type_id', $lead_types, 'IN')
->get('user_lead_types');
return sizeof($user_lead_types) > 0;
}
//Get lead types from API post and create $tags
$lead_types = $this->request['leadData']['lead_types'];
$strTags = array();
if(!empty($lead_types))
$strTags = explode(',',$lead_types);
$tags = '';
$lead_types_objects = $db->where('lead_type', $strTags,'IN')->get('lead_types');
foreach($lead_types_objects as $l)
{
if($tags=='')
$tags = $l['id'];
else
$tags.=',' .$l['id'];
}
We then send them a SMS if the form tags matched the users cloud tags. 然后,如果表单标签与用户云标签匹配,我们将向他们发送一条SMS。
global $sid,$token;
$client = new Twilio\Rest\Client($sid, $token);
$content_data = [
"leadname" => $posted_name,
"leadzipcode" => $posted_zipcode,
"leadphone" => $posted_phone,
"leademail" => $posted_email,
"leadtags" => $lead_types
];
//Replace Content
foreach($content_data as $index => $value){
$lead_sms_template = str_replace("|".$index."|", $value, $lead_sms_template);
}
// Step 5: Loop over all our friends. $number is a phone number above, and
// $name is the name next to it
foreach ($people as $person) {
try{
//commented temporarily -- uncommented below to try to solve issue of texting everyone still
if($this->has_lead_type_selected($person['ID'],$tags))
{
$number = $person['phone_no'];
$name = $person['first_name']. ' '. $person['last_name'];
Thank you for the help. 感谢您的帮助。
In the 2nd line of code global $db
, $tags
; 在第二行代码global $db
, $tags
; was overwriting if($this->has_lead_type_selected($person['ID'],$tags))
which caused the global $tags
to overwrite $tags
at the lower portion of code. 正在覆盖if($this->has_lead_type_selected($person['ID'],$tags))
,这导致全局$tags
覆盖$tags
下部的$tags
。 So the global var was empty because it was before the actual $tags
var was given a function. 所以全局$tags
是空的,因为它是在给实际的$tags
var函数之前。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.