How to get result from another column of array?

How to get result from another column of array?

kenionatankenionatan Posts: 4Questions: 2Answers: 0

It's possible to get two column values in one array?
for example, I want to get the "order_id" and the "status" in one array:

$table = 'order_client_view';
$primaryKey = 'id_order';

$columns = array(
    array( 'db' => 'id_order', 'dt' => 0 ),
    array( 'db' => 'id_client',  'dt' => 1 ),
    array( 'db' => utf8_encode('client_name'), 'dt' => 2 ),
    array(
         'db'        => 'status',
         'dt'        => 3,
         'formatter' => function( $d, $row ) {
             if($d == 0){
                $selecao = '<form method="post" action="?pagina=update_status">';
                $selecao .= '<input type="hidden" name="id_order" value="'.HERE I WANT TO PUT THE id_order.'">';
                $selecao .= '<select style="font-size:10px;" onchange="this.form.submit();" name="status_select">';
                $selecao .= '<option value="0">New Order</option>';
                $selecao .= '<option value="1">Preparing</option>';
                $selecao .= '<option value="2">Delivering</option>';
                $selecao .= '<option value="3">Finished</option>';
                $selecao .= '</select>';
                $selecao .= '</form>';
            }
        }
    )
);

In the array[3], the $d inside the function is the status code,
I want to put the id_order that is in the array[0].
Is it possible?
Thanks.

Answers

  • allanallan Posts: 63,212Questions: 1Answers: 10,415 Site admin

    You can use a rendering function on the client-side to combine two data values into a single column for display in the table.

    Allan

  • kenionatankenionatan Posts: 4Questions: 2Answers: 0

    Thank you Allan,

    I used another solution to solve this problem, in the server side.
    I will let the solution here, because it can be the solution for someone's problem:

           'formatter' => function( $d, $row ) {
                header('Content-Type: text/html; charset=utf-8');
                $connect = mysqli_connect("localhost", "user", "password", "database");
                mysqli_set_charset( $connect, 'utf8');
                $query = "SELECT * FROM `order_client_view` WHERE id_order = '".$d."'";
                $result = mysqli_query($connect, $query);
                $row = mysqli_fetch_assoc($result);
                $order_number = $d;
                 if($row[status] == 0){
                    $selecao = '<form method="post" action="?pagina=update_status">';
                    $selecao .= '<input type="hidden" name="id_order" value="'.$order_number.'">';
                    $selecao .= '<select style="font-size:10px;" onchange="this.form.submit();" name="status_select">';
                    $selecao .= '<option value="0">New Order</option>';
                    $selecao .= '<option value="1">Preparing</option>';
                    $selecao .= '<option value="2">Delivering</option>';
                    $selecao .= '<option value="3">Finished</option>';
                    $selecao .= '</select>';
                    $selecao .= '</form>';
                 }
           }
    
This discussion has been closed.