Hi there,
Currently trying to populate a dropdown list in my form with the result of a query that use join and calculation. the actual way i try to achieve it , is with a custom code.
The code looks this way.
So my code is Alrigth as i can see from the "print_r" function in the top of my form it returns me :
so great what i know want to to is to put thes value in my dropdown, BUT with key and value.
like:
4=MSPI-MNE_formerge
3=MSPI-GIPI
4=MSPI-MNE
5=LPRO-PPO
...... and so on.
i thougth that the embedded function
a little help would be great.
Thanks a lot.
Currently trying to populate a dropdown list in my form with the result of a query that use join and calculation. the actual way i try to achieve it , is with a custom code.
The code looks this way.
<?php // Connect to MySQL. $link = new mysqli('myhost', 'user', 'password', 'db'); if ( $link->connect_errno ) { die( "Failed to connect to MySQL: (" . $link->connect_errno . ") " . $link->connect_error ); } // Get the datas from the database. $query1 = "SELECT 'here_comes_the_first_query from table 1';"; $result = $link->query($query); // Extract the datas returned by the query1 and insert it in an array. $data = array(); while ( $row = $result->fetch_assoc() ) { $data[] = $row; $query2 = "SELECT 'here_comes_the_second_query from table 2';"; $result = $link->query($query); // Extract the datas returned by the query and insert it in an array. $data = array(); while ( $row = $result->fetch_assoc() ) { $data2[] = $row; // Merge 2 array. $mergedresult = array_merge($data, $data2); print_r($mergedresult); $form->data['Mydropdownlist_fieldID'] = $mergedresult; //this part doesn't work ?>
So my code is Alrigth as i can see from the "print_r" function in the top of my form it returns me :
Array ( [0] => Array ( [id] => 4 [formation] => MSPI-MNE_formerge ) [1] => Array ( [id] => 3 [formation] => MSPI-GIPI ) [2] => Array ( [id] => 4 [formation] => MSPI-MNE ) [3] => Array ( [id] => 5 [formation] => LPRO-PPO ) [4] => Array ( [id] => 7 [formation] => LPRO-LIEE ) )
so great what i know want to to is to put thes value in my dropdown, BUT with key and value.
like:
4=MSPI-MNE_formerge
3=MSPI-GIPI
4=MSPI-MNE
5=LPRO-PPO
...... and so on.
i thougth that the embedded function
$form->data['Mydropdownlist_fieldID'] = $mergedresult, would achieve it but nothing appears in my dropdown.
a little help would be great.
Thanks a lot.