1

I don't know much about SQL. I'm trying to access this information to put it in a variable.

For example, I need to take the e-mails, the two values ​​and put them in a separate variable.

How do I make a filter to find these variables according to the email value?

    $comissao_total = $wpdb->get_results("SELECT post_content FROM wp0l_posts WHERE id = 9029");
    print_r($comissao_total);

The return I get is something like this.

Array( 
    [0] => 
    [post_content] => [
        ["Email","D\u00e9bito","Cr\u00e9dito","Identifica\u00e7\u00e3o do Vendedor"],
        ["[email protected]","725","0","[email protected]"],  
        ["[email protected]","645.5","20",
             "[email protected]"],
        ["[email protected]","200","0","[email protected]"],
        ["[email protected]","21591.2","3573.2",
             "[email protected]"]
    ] 
))

In this case it returns the array with all the data, but in fact I would need to get only the values, via email.

For example: If I want to filter the email [email protected], I need to receive 725 and 0 in two variables. Corresponding to this array ["[email protected]", "725", "0", "[email protected]"]

1 Answer 1

1

you can write yourself a function and loop thru the array with foreach

<?php
$var1 = "";
$var2 = "";

// your input array
$yourArray['0']['post_content'] = Array( [
        ["Email","D\u00e9bito","Cr\u00e9dito","Identifica\u00e7\u00e3o do Vendedor"],
        ["[email protected]","725","0","[email protected]"],  
        ["[email protected]","645.5","20","[email protected]"],
        ["[email protected]","200","0","[email protected]"],
        ["[email protected]","21591.2","3573.2","[email protected]"]
    ] );

// your filter function
function filter($email){
  global $var1;
  global $var2;
  global $yourArray;
  foreach($yourArray['0']['post_content'][0] as $var){
    foreach($var as $val){
    if($val == $email){
        $var1 = $var['1'];
        $var2 = $var['2'];
      }
    }
  }
}

//calling the function
filter("[email protected]");

// output
echo "<pre>";
echo "\$var1 = $var1 \n";
echo "\$var2 = $var2 \n";
echo "</pre>";
?>

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

1 Comment

I managed to adapt it and get a sense of which way to go, thank you very much!

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.