I have strange problem with PHP. When I set the string like '<' and if I make new string with few strings then when is go to '<' is stop to working and go to next row of the script
$a = new SomeObject();
$a->where('id', 13332, "<");
public function where($column, $param, $operator = '=') {
echo strlen($operator);
if (isset($column) && strlen($operator) > 0) {
echo $operator;
if ($operator === '>') {
$this->_where = ' WHERE ' . $column . '>?';
} else if ($operator == '<') {
$this->_where = ' WHERE ' . $column . '<?';
} else if ($operator === '=') {
$this->_where = ' WHERE ' . $column . '=?';
} else {
$this->_where = ' WHERE ' . $column . $operator . '?';
}
$this->_where = ' WHERE ' . $column . chr(0x3c) . '?';
echo '<br/>' . $this->_where . '<br/>';
} else {
throw new \Exception('We need to have $column variable like string and $param like Param!', 500);
}
echo '<br/>c';
}
And the result is:
1< WHERE id c
And my question is why less < is cannot get like string. The > and = operators is OK. But the < just is not recognize. What I'm doing wrong?
Remove one line and it will work (test one below yourself):-
<?php
error_reporting(E_ALL); //check all type of errors
ini_set('display_errors',1); // display those if any happen
$a = new SomeObject();
$a->where('id', 13332, "<");
public function where($column, $param, $operator = '=') {
echo strlen($operator);
if (isset($column) && strlen($operator) > 0) {
echo $operator;
if ($operator === '>') {
$this->_where = ' WHERE ' . $column . '> ?'; // added space
} else if ($operator == '<') {
$this->_where = ' WHERE ' . $column . '< ?'; // added space
} else if ($operator === '=') {
$this->_where = ' WHERE ' . $column . '= ?'; // added space
} else {
$this->_where = ' WHERE ' . $column . $operator . '?';
}
//$this->_where = ' WHERE ' . $column . chr(0x3c) . '?'; remove this line
echo '<br/>' . $this->_where . '<br/>';
} else {
throw new \Exception('We need to have $column variable like string and $param like Param!', 500);
}
echo '<br/>c';
}
Note:-
Reason for not working:-
You have to add spaces too to make it correct(commented by #RiggsFolly) (For browser showing sake)
You are just over-writing your conditions. (commented and example by #JonStirling :- https://3v4l.org/vCO5Z) (for working purpose)
In this line:
$this->_where = ' WHERE ' . $column . chr(0x3e) . '?';
you overwrite your all previous changes so no wonder you can not see right result
Please try with this function and let me know will it gives you desired output
public function where($column, $param, $operator = '=') {
echo strlen($operator);
if (isset($column) && strlen($operator) > 0) {
echo $operator;
if ($operator === '>') {
$this->_where = ' WHERE ' . $column . '> ?';
} else if ($operator == '<') {
$this->_where = ' WHERE ' . $column . '< ?';
} else if ($operator === '=') {
$this->_where = ' WHERE ' . $column . '= ?';
} else {
$this->_where = ' WHERE ' . $column . $operator . ' ?';
}
if($this->_where != '')
{
$this->_where .= ' and ' . $column . chr(0x3e) . ' ?';
}
else
{
$this->_where = ' WHERE ' . $column . chr(0x3e) . ' ?';
}
echo '<br/>' . $this->_where . '<br/>';
} else {
throw new \Exception('We need to have $column variable like string and $param like Param!', 500);
}
echo '<br/>c';
}
Related
I have a form that sends customer data to the database, I added a choice of another category of customers through the input, and instead of sending the data in text, a number is sent.
db
In View
<?php echo render_select('sellers',get_sellers(),array('articleid','subject'),''); ?>
echo render_select helper:
function render_select($name, $options, $option_attrs = [], $label = '', $selected = '', $select_attrs = [], $form_group_attr = [], $form_group_class = '', $select_class = '', $include_blank = true)
{
$callback_translate = '';
if (isset($options['callback_translate'])) {
$callback_translate = $options['callback_translate'];
unset($options['callback_translate']);
}
$select = '';
$_form_group_attr = '';
$_select_attrs = '';
if (!isset($select_attrs['data-width'])) {
$select_attrs['data-width'] = '100%';
}
if (!isset($select_attrs['data-none-selected-text'])) {
$select_attrs['data-none-selected-text'] = _l('dropdown_non_selected_tex');
}
foreach ($select_attrs as $key => $val) {
// tooltips
if ($key == 'title') {
$val = _l($val);
}
$_select_attrs .= $key . '=' . '"' . $val . '" ';
}
$_select_attrs = rtrim($_select_attrs);
$form_group_attr['app-field-wrapper'] = $name;
foreach ($form_group_attr as $key => $val) {
// tooltips
if ($key == 'title') {
$val = _l($val);
}
$_form_group_attr .= $key . '=' . '"' . $val . '" ';
}
$_form_group_attr = rtrim($_form_group_attr);
if (!empty($select_class)) {
$select_class = ' ' . $select_class;
}
if (!empty($form_group_class)) {
$form_group_class = ' ' . $form_group_class;
}
$select .= '<div class="select-placeholder form-group' . $form_group_class . '" ' . $_form_group_attr . '>';
if ($label != '') {
$select .= '<label for="' . $name . '" class="control-label">' . _l($label, '', false) . '</label>';
}
$select .= '<select id="' . $name . '" name="' . $name . '" class="selectpicker' . $select_class . '" ' . $_select_attrs . ' data-live-search="true">';
if ($include_blank == true) {
$select .= '<option value=""></option>';
}
foreach ($options as $option) {
$val = '';
$_selected = '';
$key = '';
if (isset($option[$option_attrs[0]]) && !empty($option[$option_attrs[0]])) {
$key = $option[$option_attrs[0]];
}
if (!is_array($option_attrs[1])) {
$val = $option[$option_attrs[1]];
} else {
foreach ($option_attrs[1] as $_val) {
$val .= $option[$_val] . ' ';
}
}
$val = trim($val);
if ($callback_translate != '') {
if (function_exists($callback_translate) && is_callable($callback_translate)) {
$val = call_user_func($callback_translate, $key);
}
}
$data_sub_text = '';
if (!is_array($selected)) {
if ($selected != '') {
if ($selected == $key) {
$_selected = ' selected';
}
}
} else {
foreach ($selected as $id) {
if ($key == $id) {
$_selected = ' selected';
}
}
}
if (isset($option_attrs[2])) {
if (strpos($option_attrs[2], ',') !== false) {
$sub_text = '';
$_temp = explode(',', $option_attrs[2]);
foreach ($_temp as $t) {
if (isset($option[$t])) {
$sub_text .= $option[$t] . ' ';
}
}
} else {
if (isset($option[$option_attrs[2]])) {
$sub_text = $option[$option_attrs[2]];
} else {
$sub_text = $option_attrs[2];
}
}
$data_sub_text = ' data-subtext=' . '"' . $sub_text . '"';
}
$data_content = '';
if (isset($option['option_attributes'])) {
foreach ($option['option_attributes'] as $_opt_attr_key => $_opt_attr_val) {
$data_content .= $_opt_attr_key . '=' . '"' . $_opt_attr_val . '"';
}
if ($data_content != '') {
$data_content = ' ' . $data_content;
}
}
$select .= '<option value="' . $key . '"' . $_selected . $data_content . $data_sub_text . '>' . $val . '</option>';
}
$select .= '</select>';
$select .= '</div>';
return $select;
}
get sellers arrays in db functions
function get_sellers()
{
$CI = & get_instance();
return $CI->db->get(db_prefix() . 'sellers')->result_array();
}
I have created a column "sellers" in my table but it sends numbers and not text.
I need it so that when the form is saved it will submit the title and display it in the selection.
Thanks you
View form:
click
I am using the Divi Theme.
The shortcode is working, however it is displaying directly under the header rather than where I place the shortcode within the Divi Builder.
I read more about WP shortcodes and it looked like we should be using return rather than echo, but when I change it to return it does not display at all on the page.
Thanks!
function breadcrumb() {
$delimiter = '»'; // delimiter between crumbs
$home = 'Home'; // text for the 'Home' link
$showCurrent = 1; // 1 - show current post/page title in breadcrumbs, 0 - don't show
$before = '<span class="current">'; // tag before the current crumb
$after = '</span>'; // tag after the current crumb
global $post;
$homeLink = get_bloginfo('url');
echo '<div id="crumbs">' . $home . ' ' . $delimiter . ' ';
if (is_single() && !is_attachment()) {
if (get_post_type() != 'post') {
$post_type = get_post_type_object(get_post_type());
$slug = $post_type->rewrite;
return '' . $post_type->labels->singular_name . '';
if ($showCurrent == 1) {
return ' ' . $delimiter . ' ' . $before . get_the_title() . $after;
}
} else {
$cat = get_the_category();
$cat = $cat[0];
$cats = get_category_parents($cat, true, ' ' . $delimiter . ' ');
if ($showCurrent == 0) {
$cats = preg_replace("#^(.+)\s$delimiter\s$#", "$1", $cats);
}
echo $cats;
if ($showCurrent == 1) {
echo $before . get_the_title() . $after;
}
}
} elseif (!is_single() && !is_page() && get_post_type() != 'post' && !is_404()) {
$post_type = get_post_type_object(get_post_type());
return $before . $post_type->labels->singular_name . $after;
} elseif (is_attachment()) {
$parent = get_post($post->post_parent);
$cat = get_the_category($parent->ID);
$cat = $cat[0];
return get_category_parents($cat, true, ' ' . $delimiter . ' ');
echo '' . $parent->post_title . '';
if ($showCurrent == 1) {
echo ' ' . $delimiter . ' ' . $before . get_the_title() . $after;
}
} elseif (is_page() && !$post->post_parent) {
if ($showCurrent == 1) {
return $before . get_the_title() . $after;
}
} elseif (is_page() && $post->post_parent) {
$parent_id = $post->post_parent;
$breadcrumbs = array();
while ($parent_id) {
$page = get_page($parent_id);
$breadcrumbs[] = '' . get_the_title($page->ID) . '';
$parent_id = $page->post_parent;
}
$breadcrumbs = array_reverse($breadcrumbs);
for ($i = 0; $i < count($breadcrumbs); $i++) {
return $breadcrumbs[$i];
if ($i != count($breadcrumbs)-1) {
return ' ' . $delimiter . ' ';
}
}
if ($showCurrent == 1) {
return ' ' . $delimiter . ' ' . $before . get_the_title() . $after;
}
}
return '</div>';
}
function breadcrumb() {
$delimiter = '»'; // delimiter between crumbs
$home = 'Home'; // text for the 'Home' link
$showCurrent = 1; // 1 - show current post/page title in breadcrumbs, 0 - don't show
$before = '<span class="current">'; // tag before the current crumb
$after = '</span>'; // tag after the current crumb
global $post;
$homeLink = get_bloginfo('url');
$bredcrumb = '<div id="crumbs">' . $home . ' ' . $delimiter . ' ';
if (is_single() && !is_attachment()) {
if (get_post_type() != 'post') {
$post_type = get_post_type_object(get_post_type());
$slug = $post_type->rewrite;
$bredcrumb .='' . $post_type->labels->singular_name . '';
if ($showCurrent == 1) {
$bredcrumb .=' ' . $delimiter . ' ' . $before . get_the_title() . $after;
}
} else {
$cat = get_the_category();
$cat = $cat[0];
$cats = get_category_parents($cat, true, ' ' . $delimiter . ' ');
if ($showCurrent == 0) {
$cats = preg_replace("#^(.+)\s$delimiter\s$#", "$1", $cats);
}
$bredcrumb .= $cats;
if ($showCurrent == 1) {
$bredcrumb .= $before . get_the_title() . $after;
}
}
} elseif (!is_single() && !is_page() && get_post_type() != 'post' && !is_404()) {
$post_type = get_post_type_object(get_post_type());
$bredcrumb .= $before . $post_type->labels->singular_name . $after;
} elseif (is_attachment()) {
$parent = get_post($post->post_parent);
$cat = get_the_category($parent->ID);
$cat = $cat[0];
$bredcrumb .= get_category_parents($cat, true, ' ' . $delimiter . ' ');
$bredcrumb .= '' . $parent->post_title . '';
if ($showCurrent == 1) {
$bredcrumb .= ' ' . $delimiter . ' ' . $before . get_the_title() . $after;
}
} elseif (is_page() && !$post->post_parent) {
if ($showCurrent == 1) {
$bredcrumb .= $before . get_the_title() . $after;
}
} elseif (is_page() && $post->post_parent) {
$parent_id = $post->post_parent;
$breadcrumbs = array();
while ($parent_id) {
$page = get_page($parent_id);
$breadcrumbs[] = '' . get_the_title($page->ID) . '';
$parent_id = $page->post_parent;
}
$breadcrumbs = array_reverse($breadcrumbs);
for ($i = 0; $i < count($breadcrumbs); $i++) {
$bredcrumb .= $breadcrumbs[$i];
if ($i != count($breadcrumbs)-1) {
$bredcrumb .= ' ' . $delimiter . ' ';
}
}
if ($showCurrent == 1) {
$bredcrumb .= ' ' . $delimiter . ' ' . $before . get_the_title() . $after;
}
}
$bredcrumb .= '</div>';
echo $bredcrumb;
return $bredcrumb;
Hello I am trying to push in an array using array_push but I am getting the value of the first index then after that all I am getting a null response, I am not getting where I have done a mistake.I am getting the values properly but in array_push there is some mistake which is in for loop.
Here is my code :
function actioncouponcsv_download() {
$this->layout = false;
foreach (Yii::app()->log->routes as $route) {
if ($route instanceof CWebLogRoute || $route instanceof CFileLogRoute || $route instanceof YiiDebugToolbarRoute) {
$route->enabled = false;
}
}
$dateRange = json_decode($_POST['dateRange'], true);
$start = $dateRange['start'];
$end = $dateRange['end'];
$validity = $_POST['validity'];
$limit = isset($_REQUEST['limit']) && trim($_REQUEST['limit']) ? $_REQUEST['limit'] : 0;
$studio_id = Yii::app()->user->studio_id;
if (isset($_GET['type']) && intval($_GET['type']) ==2) {
$couponobj = new CouponSubscription();
$getcouponobj = $couponobj->getcoupon_data($studio_id,$start,$end,$validity);
$k = 0;
$title_addon = "\t" . "Discount Cycle" . "\t" . "Extend free trail";
$data_addon = "\t" . $getcouponobj[$k]['discount_multiple_cycle'] . "\t" . $getcouponobj[$k]['extend_free_trail'];
} else {
$title_addon = "";
$data_addon = "";
$couponobj = new Coupon();
$getcouponobj = $couponobj->getcoupon_data($studio_id,$limit,1);
}
//$Coupon = Coupon::model()->find('studio_id=:studio_id', array(':studio_id' => $studio_id));
$dataCsv = '';
if ($getcouponobj) {
$headings = "Sl no" . "\t" . "Coupon" . "\t" . "Coupon Type" . "\t" . "Used by a single user" . "\t" . "Valid" . "\t" . "Used" . "\t" . "User" .$title_addon. "\t" . "Used Date". "\t" . "Content Category". "\t" . "Content"."\n";
$i = 1;
$dataCSV[] = Array();
$j = 0;
for ($k = 0; $k < count($getcouponobj); $k++) {
$userList = '-';
if ($getcouponobj[$k]['used_by'] != '0') {
if ($getcouponobj[$k]['coupon_type'] == 1) {
$userList = '';
$userIdList = explode(",", $getcouponobj[$k]['used_by']);
foreach ($userIdList as $userIdListKey => $userIdListVal) {
if ($userIdListKey == 0) {
$userList .= Yii::app()->webCommon->getuseremail($userIdListVal);
} else {
$userList .= " | " . Yii::app()->webCommon->getuseremail($userIdListVal);
}
}
} else {
$userList = Yii::app()->webCommon->getuseremail($getcouponobj[$k]['used_by']);
}
}
if($getcouponobj[$k]['is_all']!=1){
if($getcouponobj[$k]['content_category']==1){
$cont_cat = "Digital";
$content_str = Coupon::model()->getContentInfo($getcouponobj[$k]['specific_content']);
$cont_str = $content_str;
}else if($getcouponobj[$k]['content_category']==2){
$cont_cat = "Physical";
$content_str = Coupon::model()->getContentInfoPhysical($getcouponobj[$k]['specific_content']);
$cont_str = $content_str;
}else{
$cont_cat = "All";
$cont_str = "All";
}
}else{
$cont_cat = "All";
$cont_str = "All";
}
#echo $getcouponobj[$k]['coupon_code'];
array_push($dataCSV[$j],$i);
array_push($dataCSV[$j],$getcouponobj[$k]['coupon_code']);
array_push($dataCSV[$j],(($getcouponobj[$k]['coupon_type'] == 1) ? 'Multi-use' : 'Once-use'));
array_push($dataCSV[$j],(($getcouponobj[$k]['user_can_use'] == 1) ? 'Multiple times' : 'Once'));
array_push($dataCSV[$j],(($getcouponobj[$k]['used_by'] == 0) ? 'Yes' : 'No'));
array_push($dataCSV[$j],(($getcouponobj[$k]['used_by'] == 0) ? '-' : 'Yes'));
array_push($dataCSV[$j],$userList);
array_push($dataCSV[$j],$getcouponobj[$k]['discount_multiple_cycle']);
array_push($dataCSV[$j],$getcouponobj[$k]['extend_free_trail']);
array_push($dataCSV[$j],(($getcouponobj[$k]['cused_date'] == 0) ? '-' : $getcouponobj[$k]['cused_date']));
array_push($dataCSV[$j],$cont_cat);
array_push($dataCSV[$j],$cont_str);
$j++;
//$dataCsv .= $i . "\t" . $getcouponobj[$k]['coupon_code'] . "\t" . (($getcouponobj[$k]['coupon_type'] == 1) ? 'Multi-use' : 'Once-use') . "\t" . (($getcouponobj[$k]['user_can_use'] == 1) ? 'Multiple times' : 'Once') . "\t" . (($getcouponobj[$k]['used_by'] == 0) ? 'Yes' : 'No') . "\t" . (($getcouponobj[$k]['used_by'] == 0) ? '-' : 'Yes') . "\t" . $userList .$data_addon. "\t" . (($getcouponobj[$k]['cused_date'] == 0) ? '-' : $getcouponobj[$k]['cused_date'])."\t" .$cont_cat ."\t".$cont_str."\n";
$i = $i+1;
}
}
print_r(json_encode($dataCSV));
}
PS: I am getting the values. Any help will be highly appreciated.
Well, first thing i see wrong is the way you declare your array:
$dataCSV[] = Array();
$array[] = Means that you are adding a new value to an existing array. To declare your array you should use
$dataCSV = array();
Also, this code:
array_push($dataCSV[$j],$i);
means that you are adding a new value to your $dataCSV[$j] array, but this is never declared as an array, so first thing would be to do
$dataCSV[$j] = new array();
Your code is really long and complicated, those are only examples of issues i see in there.
I am trying to improve the below switch statement. What's happening here is that the code is called multiple times based on an x amount of tokens found, so the below code runs once per token.
If the $post->ID is not found then a notification is sent to that token and the id gets added in the database.
This works however at some point it's stopping after around 40% of tokens checked presumably because the ID is found? Since I am on wordpress, I used the update_option to store the id in a table but perhaps an alternative approach can be used?
$os = $this->os;
switch ($os) {
case "iOS":
$iOS_pastPushSavedID = get_option( 'iOS_pastPushSavedID', $default = false);
if($post->ID != $iOS_pastPushSavedID) {
update_option( 'iOS_pastPushSavedID', $post->ID, no);
$sendPush = true;
//$title = ($os . '_New Push = ' . ' storedID: ' . $iOS_pastPushSavedID . ' / postID: ' . $post->ID);
} else {
//$title = ($os . '_Duplicate Push = ' . ' storedID: ' . $iOS_pastPushSavedID . ' / postID: ' . $post->ID);
$sendPush = false;
}
break;
case "Android":
$android_pastPushSavedID = get_option( 'android_pastPushSavedID', $default = false);
if($post->ID != $android_pastPushSavedID) {
//$title = ($os . '_New Push = ' . ' storedID: ' . $android_pastPushSavedID . ' / postID: ' . $post->ID);
update_option( 'android_pastPushSavedID', $post->ID, no);
$sendPush = true;
} else {
//$title = ($os . '_Duplicate Push = ' . ' storedID: ' . $android_pastPushSavedID . ' / postID: ' . $post->ID);
$sendPush = false;
}
break;
case "Fire OS":
$fireos_pastPushSavedID = get_option( 'fireos_pastPushSavedID', $default = false);
if($post->ID != $fireos_pastPushSavedID) {
//$title = ($os . '_New Push = ' . ' storedID: ' . $fireos_pastPushSavedID . ' / postID: ' . $post->ID);
update_option( 'fireos_pastPushSavedID', $post->ID, no);
$sendPush = true;
} else {
//$title = ($os . '_Duplicate Push = ' . ' storedID: ' . $fireos_pastPushSavedID . ' / postID: ' . $post->ID);
$sendPush = false;
}
break;
case "Safari":
$safari_pastPushSavedID = get_option( 'safari_pastPushSavedID', $default = false);
if($post->ID != $safari_pastPushSavedID) {
//$title = ($os . '_New Push = ' . ' storedID: ' . $safari_pastPushSavedID . ' / postID: ' . $post->ID);
update_option( 'safari_pastPushSavedID', $post->ID, no);
$sendPush = true;
} else {
//$title = ($os . '_Duplicate Push = ' . ' storedID: ' . $safari_pastPushSavedID . ' / postID: ' . $post->ID);
$sendPush = false;
}
break;
case "Chrome":
$chrome_pastPushSavedID = get_option( 'chrome_pastPushSavedID', $default = false);
if($post->ID != $chrome_pastPushSavedID) {
//$title = ($os . '_New Push = ' . ' storedID: ' . $chrome_pastPushSavedID . ' / postID: ' . $post->ID);
update_option( 'chrome_pastPushSavedID', $post->ID, no);
$sendPush = true;
} else {
//$title = ($os . '_Duplicate Push = ' . ' storedID: ' . $chrome_pastPushSavedID . ' / postID: ' . $post->ID);
$sendPush = false;
}
break;
case "Firefox":
$firefox_pastPushSavedID = get_option( 'firefox_pastPushSavedID', $default = false);
if($post->ID != $firefox_pastPushSavedID) {
//$title = ($os . '_New Push = ' . ' storedID: ' . $firefox_pastPushSavedID . ' / postID: ' . $post->ID);
update_option( 'firefox_pastPushSavedID', $post->ID, no);
$sendPush = true;
} else {
//$title = ($os . '_Duplicate Push = ' . ' storedID: ' . $firefox_pastPushSavedID . ' / postID: ' . $post->ID);
$sendPush = false;
}
break;
default:
$sendPush = false;
}
Unless I am misunderstanding your process, this is a very DRY / concise way to do it without the verbose switch/case block:
$os_opts=[
'iOS'=>'iOS',
'Android'=>'android',
'Fire OS'=>'fireos',
'Safari'=>'safari',
'Chrome'=>'chrome',
'Firefox'=>'firefox'
];
$os=$this->os;
$sendPush=false;
if(isset($os_opts[$os])){ // deny empty and invalid options
$os_opt="{$os_opts[$os]}_pastPushSavedID"; // build string for next two functions
if($post->ID!=get_option($os_opt,$default=false)){
update_option($os_opt,$post->ID,no);
$sendPush = true;
}
}
The $os_opts array has keys that match $os, and values that work with get_option() & update_option(). This will largely reduce code length, and make future modifications very easy to do.
Since the get_option() result is only used once, it doesn't make sense to declare it as a variable; just use it in the if condition.
The first parameter of get_option() and update_option() always end with the same substring. I makes sense to prepend the $os_opts[$os] value to it and declare it as a variable. The variable declaration is not necessary but my personal rule is; if you are going to use data more than once use a variable, if only once don't declare it.
You can do it like this. You can shorten your code like this.
$optionName='';//added some default values
$sendPush = false;;//added some default values
switch ($os) {
case "iOS":
$optionName='iOS_pastPushSavedID';
break;
case "Android":
$optionName='android_pastPushSavedID';
break;
case "Fire OS":
$optionName='fireos_pastPushSavedID';
break;
case "Safari":
$optionName='safari_pastPushSavedID';
break;
case "Chrome":
$optionName='chrome_pastPushSavedID';
break;
case "Firefox":
$optionName='firefox_pastPushSavedID';
break;
default:
$sendPush = false;
}
//this is operation which is common when $optionName is not empty.
if(!empty($optionName))
{
$optionData = get_option($optionName, $default = false);
if($post->ID != $optionData) {
update_option( $optionData, $post->ID, no);
$sendPush = true;
} else {
$sendPush = false;
}
}
Id write it more like this
function getOptionSpecifier() {
switch ($this->os) {
case "iOS":
return 'iOS_pastPushSavedID';
case "Android":
return 'android_pastPushSavedID';
case "Android":
return 'android_pastPushSavedID';
case "Fire OS":
return 'fireos_pastPushSavedID';
case "Safari":
return 'safari_pastPushSavedID';
case "Chrome":
return 'chrome_pastPushSavedID';
case "Firefox":
return 'firefox_pastPushSavedID';
default:
return '';
}
}
function send_notification($id) {
$optionSpecifier = getOptionSpecifier();
if ($optionSpecifier === NULL) {
return false;
}
$pastPushSavedID = get_option( $optionSpecifier, $default = false);
if($id != $pastPushSavedID) {
update_option( $optionSpecifier, $id, no);
return true;
//$title = ($os . '_New Push = ' . ' storedID: ' . $iOS_pastPushSavedID . ' / postID: ' . $post->ID);
} else {
//$title = ($os . '_Duplicate Push = ' . ' storedID: ' . $iOS_pastPushSavedID . ' / postID: ' . $post->ID);
return false;
}
}
$sendPush = send_notification($post->ID);
Multiple functions ala "separation of concerns" and so ...
I have a method that updated fields in a table. Its used to update three tables, invoices invoice_items and payments All three tables have the same field to be updated. When the below code runs, the multi_checked() method runs for the first two times, but not for the third time and It's not obvious to me as to why. Any Ideas?
Method Call:
elseif (isset($_POST[$mod . '-del']) && count($check) > 0) {
$state = multi_checked(
$check,
'UPDATE ' . $db['database'] . '.invoices SET deleted="Y"',
EVENT_DEL,
'Invoice [' . $c . '] deleted',
'Please select at least one item',
FALSE,
'SELECT id FROM ' . $db['database'] . '.invoices'
);
$state = multi_checked(
$check,
'UPDATE ' . $db['database'] . '.payments SET deleted="Y"',
EVENT_DEL,
'Payment [' . $c . '] deleted',
'Please select at least one item',
TRUE,
'SELECT id FROM ' . $db['database'] . '.payments',
null,
"id_invoice"
);
$state = multi_checked(
$check,
'UPDATE ' . $db['database'] . '.invoice_items SET deleted="Y"',
EVENT_DEL,
'Invoice Item [' . $c . '] deleted',
'Please select at least one item',
TRUE,
'SELECT id FROM ' . $db['database'] . '.invoice_items',
null,
"id_invoice"
);
} # Clear Export timestamps
the multi_checked method is described as follows:
function multi_checked(
$check,
$query,
$event_type,
$event_desc,
$none = 'Please select at least one item',
$redirect = TRUE,
$meta_query = NULL,
$success_msg = NULL,
$field = "id"
) {
global $db, $mod;
$batch_count = count($check);
$meta_data = NULL;
if ($batch_count == 0) {
add_msg($none);
return (0);
} else {
$changed = 0;
$ref = load_array('SELECT MAX(id) FROM ' . $db['database'] . '.eventlog'); # batch id
foreach ($check As $c) {
if ($meta_query != NULL) {
$meta_data = load_array($meta_query . ' WHERE id' . $field . '="' . $c . '"');
if ($meta_data != NULL) $meta_data = ' (' . $meta_data . ')';
}
$q = $query . ' WHERE ' . $field . '="' . $c . '"';
$z = $query . ' WHERE ' . $field . '="' . $c . '"';
$g = "asf";
if (run_query($query . ' WHERE ' . $field . '="' . $c . '"') == 0) {
eventlog($db['database'], $event_type, $mod, $c, uid(), '[Batch #' . $ref . '] ' . $event_desc . $meta_data, uname());
$changed++;
} else {
eventlog($db['database'], $event_type, $mod, $c, uid(), '[Batch #' . $ref . '] FAIL: ' . $event_desc . $meta_data, uname(), FALSE, FALSE);
}
}
# Check for errors
if ($changed != $batch_count) {
add_error($changed . ' of ' . $batch_count . ' items processed - you may need to check the system log for details');
} # Success!
else {
$message = ($changed . ' item' . ($changed > 1 ? 's' : NULL) . ' processed successfully');
if ($changed > 1) { # log batch summary
#mysql_query("FLUSH QUERY CACHE");
eventlog($db['database'], $event_type, $mod, 0, uid(), '[Batch #' . $ref . '] ' . $changed . ' records processed', uname());
}
# Redirect
if ($redirect) {
header('Location: ?m=' . $mod . '&changed=' . $changed . '&message=' . $success_msg);
exit;
} else {
add_msg($message);
}
}
return ($changed);
}
}
The second call to multi_check has $redirect parameter set to TRUE - so the function redirects, preventing the script to call the function the third time...