How can I create a dynamic array in php

0

I am working on a system where I have two tables in question .. the first one is wp_prflxtrflds_user_field_data that has saved the departamento, nro de interno y sucursal de un usuario . The problem is that these three data are stored in a field called user_value , and I can distinguish if it is a department or something else through a field called field_id . The second one is the wp_users field that has the user's name and email. On the other hand I have a table where I want to show .. then I ran into the problem that if I want to show the department, the branch and its internal number brings me in 3 records ... repeating the name, the email but it obviously brings me the department and branch in different registers because it's really like that.

Then to show orderly I did it this way ..

$sql="SELECT d.user_id, d.field_id, d.user_value,
                            u.ID, u.display_name, u.user_email
                            FROM wp_prflxtrflds_user_field_data as d,
                            wp_users as u
                            WHERE (d.user_id = 675) 
                            and (u.ID = d.user_id) 
                            and (d.field_id = 3 or d.field_id = 1 or d.field_id = 4)";
                        $result=mysqli_query($con,$sql);
                        $pila = array();
                        if (mysqli_num_rows($result) > 0) {
                            while($row=mysqli_fetch_array($result,MYSQLI_ASSOC)) {
                               if (!in_array($row["display_name"], $pila)) {
                                   array_push($pila, $row["display_name"]);
                               }
                               if (!in_array($row["user_email"], $pila)) {
                                   array_push($pila, $row["user_email"]);
                               }
                               if ($row["field_id"] == 3) {
                                   array_push($pila, $row["user_value"]);
                               } else if ($row["field_id"] == 1) {
                                   array_push($pila, $row["user_value"]);
                               } else if ($row["field_id"] == 4) {
                                   array_push($pila, $row["user_value"]);
                               }
                            } 
                        }
                        echo "<td>".$pila[0]."</td>";   
                        echo "<td>".$pila[1]."</td>";
                        echo "<td>".$pila[2]."</td>";    
                        echo "<td>".$pila[3]."</td>";   
                        echo "<td>".$pila[4]."</td>";

That the only thing he does is to bring the user's records and load them into an array without repeating them. but only works for a specific user .. because if I bring all the records they will load me all in the same array and there I have no idea how to display them in order ... Any help?

    
asked by Hernan Chaparro 23.11.2018 в 15:20
source

0 answers