minifairy in the table of operators and precedence they are both listed as left and logical.
But and
has significantly lower precedence.
minifairy Not sure what you meant by this? the mailing list is a separate db with a separate connect and password not a table in the same db.
I'm talking about this update:
$queryub="update `bonus` set `maillist`='".$tday."' where `id`='".$row->id."'";
I assumed the bonus
table was in the same database as the bonus
table.
minifairy The routine works but I was just getting warnings on some of the indexes in the exploded array. I would guess that whether I loaded it into a multi dimensional array in the beginning or exploded the array as I step through it the result in that case would be the same. For me loading a single array with the pipe delimiters (|) is easy, and I find it easier to follow in the code. I suppose there is one extra step the exploding but I don't have to worry about overlapping variables with variables already used etc. or come up with something short and sweet to call the secondary keys.
"Easy" is a matter of debate but in that very same paragraph you say you were having problems with it.
I was suggesting this bit:
$custshop=(isset($cnfig['cust_shop']))?$cnfig['cust_shop']:$_SESSIOn['shop'];
$query="select bonus.id, bonus.custid, bonus.bonus, bonus.wdisc,cust.lname, cust.fname, cust.email, bonus.pdate,bonus.maillist from `bonus`, `cust` where bonus.custid=cust.id and bonus.shop='".$custshop."'and cust.email!=''";
$x=1;
$result=querymeres($query);
if(is_object($result)and $result->num_rows>='1'){
while($row =$result->fetch_object()){
if($row->wdisc>"1"){
$custtype="wholesale";
}else{
$custtype="retail";
}
#accumulate the ones to be updated into an array. and update bonus file.
if(($row->pdate>$row->maillist )| $row->maillist==NULL){#recent purchase
$mlist[$x]=$row->id."|".$row->email."|".$row->fname."|".$row->lname."|".$row->bonus."|".$custtype."|";
$queryub="update `bonus` set `maillist`='".$tday."' where `id`='".$row->id."'";
queryme($queryub);
$x++;
}
}
becoming this:
$custshop = $cnfig['cust_shop'] ?? $_SESSIOn['shop']; // "$SESSIOn"?
$list_query = "Select
bonus.id,
bonus.custid,
bonus.bonus,
IF(bonus.wdisc>1, 'wholesale', 'retail') AS wdisc,
cust.lname,
cust.fname,
cust.email,
bonus.pdate,
bonus.maillist
From
bonus,
cust
Where
bonus.custid=cust.id
and bonus.shop='$custshop'
and cust.email!=''
and (bonus.maillist is null or bonus.pdate > bonus.maillist)";
// Apparently pdate can also be null. What is supposed to happen here if it is?
$result = querymeres($list_query);
$mlist = $result->fetch_all(MYSQLI_ASSOC);
if(!empty($mlist))
{
$ub_query = "Update bonus set maillist='$tday'
Where id in (" . join(', ', array_column($mlist, 'id')) . ")";
queryme($ub_query);
}
And then in the next part
for($m=1;$m<=$x-1;$m++)
{
$custinfo=explode('|',$mlist[$m]);
would be
foreach($mlist as $custinfo)
{
and things like $custinfo[2]
would be $custinfo['fname']
. Names provided automatically.