Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2015
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. Array (
  2. [30] => Array (
  3. [user_id] => 2
  4. [product_id] => 4080
  5. )
  6. [31] => Array (
  7. [user_id] => 5
  8. [product_id] => 2942
  9. )
  10. [32] => Array (
  11. [user_id] => 4
  12. [product_id] => 9630
  13. )
  14. [33] => Array (
  15. [user_id] => 3
  16. [product_id] => 2542
  17. )
  18. [34] => Array (
  19. [user_id] => 7
  20. [product_id] => 1234
  21. )
  22. )
  23.  
  24. global $wpdb;
  25.  
  26. //Retrieve the bids from the database.
  27. $form_entries = $wpdb->get_results('SELECT * FROM '. $wpdb->prefix .'frm_item_metas WHERE field_id in (145,147)');
  28.  
  29. $data = array();
  30.  
  31. foreach ( $form_entries as $meta ) {
  32.  
  33. if ( ! isset($data[$meta->item_id])){
  34.  
  35. $data[$meta->item_id] = array();
  36.  
  37. }
  38.  
  39. $data[$meta->item_id][] = $meta->meta_value;
  40.  
  41. }
  42.  
  43. //rename the array keys
  44. foreach( $data as &$new_values ) {
  45. $new_values['user_id'] = $new_values[0]; unset( $new_values[0] );
  46. $new_values['product_id'] = $new_values[1]; unset( $new_values[1] );
  47. }
  48. unset($new_values);
  49.  
  50. }
  51.  
  52. Array (
  53. [30] => Array (
  54. 'user_id' => '2',
  55. 'product_id' => '4080',
  56. )
  57. [31] => Array (
  58. 'user_id' => '5',
  59. 'product_id' => '2942',
  60. )...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement