PHP MySQL / WordPress功能/忍者表格
問題描述:
I am trying to populate a drop down list of supplier names with a WordPress plugin \"Ninja Forms\" using a query to a external database connection and custom code in functions.php.
The drop down list on the form appears to be populating with the correct quantity of results (i.e. 800+ items) but instead showing [object Object] instead of the suppliers name.
The code below is where I got up to, any support on adding the queried supplier name (SUP_Name) instead of [object Object] would be of great use.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
add_filter(\'ninja_forms_render_options\',\'my_pre_population_callback\', 10, 2); function my_pre_population_callback($options, $settings) { if( $settings[\'key\'] == \'supplier_list\' ) { $connection = mysqli_connect( \"IP:port\", \"username\", \"password\", \"db\" ); if (!$connection) { die(\'Not connected : \' . mysqli_error());} $db_selected = mysqli_select_db($connection,\"db\"); if (!$db_selected) { die (\'Can\\\'t use db : \' . mysqli_error()); } $query = \"SELECT SUP_Name FROM db.sup_supplier\"; $results = mysqli_query($connection,$query); if (!$results) { die(\'Invalid query: \' . mysqli_error()); } $options = array(); $options[] = array(\"label\" => \"Select the supplier\", \"value\" => \"\"); foreach ($results as $result) { $options[] = array(\"label\" => $result, \"value\" => $result); } wp_reset_postdata(); } return $options; mysqli_close($con); } |
Thanks in advance
網友觀點:
I\'ve managed to achieve what I am after with the following
1 2 3 4 5 6 7 8 |
$options = array(); while($row = mysqli_fetch_assoc($results)) { $options[] = array ( \'label\' => $row[\'SUP_Name\'], \'value\' => $row[\'SUP_Name\'] ); } |
由於網站搬家,部分鏈接失效,如無法下載,請聯繫站長!謝謝支持!
1. 帶 [親測] 說明源碼已經被站長親測過!
2. 下載後的源碼請在24小時內刪除,僅供學慣用途!
3. 分享目的僅供大家學習和交流,請不要用於商業用途!
4. 本站資源售價只是贊助,收取費用僅維持本站的日常運營所需!
5. 本站所有資源來源於站長上傳和網路,如有侵權請郵件聯繫站長!
6. 沒帶 [親測] 代表站長時間緊促,站長會保持每天更新 [親測] 源碼 !
7. 盜版ripro用戶購買ripro美化無擔保,若設置不成功/不生效我們不支持退款!
8. 本站提供的源碼、模板、插件等等其他資源,都不包含技術服務請大家諒解!
9. 如果你也有好源碼或者教程,可以到審核區發布,分享有金幣獎勵和額外收入!
10.如果您購買了某個產品,而我們還沒來得及更新,請聯繫站長或留言催更,謝謝理解 !
GG資源網 » PHP MySQL / WordPress功能/忍者表格
1. 帶 [親測] 說明源碼已經被站長親測過!
2. 下載後的源碼請在24小時內刪除,僅供學慣用途!
3. 分享目的僅供大家學習和交流,請不要用於商業用途!
4. 本站資源售價只是贊助,收取費用僅維持本站的日常運營所需!
5. 本站所有資源來源於站長上傳和網路,如有侵權請郵件聯繫站長!
6. 沒帶 [親測] 代表站長時間緊促,站長會保持每天更新 [親測] 源碼 !
7. 盜版ripro用戶購買ripro美化無擔保,若設置不成功/不生效我們不支持退款!
8. 本站提供的源碼、模板、插件等等其他資源,都不包含技術服務請大家諒解!
9. 如果你也有好源碼或者教程,可以到審核區發布,分享有金幣獎勵和額外收入!
10.如果您購買了某個產品,而我們還沒來得及更新,請聯繫站長或留言催更,謝謝理解 !
GG資源網 » PHP MySQL / WordPress功能/忍者表格