0

Im sure this has been answered, so if you have a relevent link please let me know.

I need to pass a condition into an array. (if this is a bad idea also please offer another solution im all ears).

PHP

 $solUpdate = "";
    if($info[$i]->shortSubject == $el && $info[$i]->id != $tid){
                $solStat = $wpdb->get_content('is_ticket','ticket_id ='.$tid,'solarStatus');
                $check = solarCurl($info[$i]->id,"Tickets",false);
                $check = json_decode($check);
                if($solStat != $st){
                    $solUpdate = ("solarStatus"=>$st);
                }
                $wpdb->update('is_ticket', array('solarID'=>$info[$i]->id,$solUpdate), array('parent_ticket'=>$tid, 'solarTType'=>$check->problemtype->id));
            }

Here is what I am trying to accomplish,

If $solStat != $st, then I want to update that Row with $st, but.... $st may not always be different, so there is no actual update to do, BUT... I dont want to write an else to my if, I think thats terrible code practice. Im sure this is easy, and I have looked to find how to do this. Thank you for your help.

1 Answer 1

2

The line:

$solUpdate = ("solarStatus"=>$st);

is not valid PHP.

You can collect the columns you want to update in an array stored in $solUpdate before running the $wpdb->update() call:

$solUpdate = array();
if ($info[$i]->shortSubject == $el && $info[$i]->id != $tid) {
    $solStat = $wpdb->get_content('is_ticket', 'ticket_id='.$tid,'solarStatus');
    $check = solarCurl($info[$i]->id,"Tickets",false);
    $check = json_decode($check);

    $solUpdate['solarID'] = $info[$i]->id;
    if ($solStat != $st) {
        $solUpdate['solarStatus'] = $st;
    }

    $where = array(
        'parent_ticket' => $tid,
        'solarTType' => $check->problemtype->id
    );

    $wpdb->update('is_ticket', $solUpdate, $where);

}

Sign up to request clarification or add additional context in comments.

1 Comment

Perfect... That helped allot, I completely forgot that building an array is the best option.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.