blmg2009 Posted August 14, 2015 Share Posted August 14, 2015 Hi guys, I'm using Opencart as my webstore framework; I'm currently building a dispatch manager that will allow me to download the orders into csv files which will be later uploaded to my couriers website. In my controller I have the following array of selected orders to be sent to the dispatch manager if (isset($this->request->post['selected'])) { $orders = $this->request->post['selected']; } elseif (isset($this->request->get['order_id'])) { $orders[] = $this->request->get['order_id']; } Then in my model I have the following: public function checkForMultipleOrders($post_code, $first_name, $last_name, $orders){ $query = $this->db->query("SELECT `order_id` FROM " . DB_PREFIX . "order WHERE `shipping_postcode`='" . $post_code . "' AND `shipping_firstname`='" .$first_name . "' AND `shipping_lastname`='" . $last_name . "'"); } What I need help with is how best to work out how many orders are by the same person i.e multiple order: 1 of 3; However I need to only look for the above parameter with order_id that have been selected and are present in the $orders array. This is to stop the model finding old orders the person may have place weeks or months ago which have already been shipped. Any help on this issue would be greatly appreciated Link to comment https://forums.phpfreaks.com/topic/297779-searching-mysql-table-for-the-multiple-orders-by-the-same-person/ Share on other sites More sharing options...
blmg2009 Posted August 14, 2015 Author Share Posted August 14, 2015 I would usually use: WHERE `order_id` IN (' . implode(',', array_map('intval', $array)) . ')'; but my array is not like array(1,2,3); it's like the following [0] => 3 [1] => 2 [2] => 1Which I'm struggling to find the correct way to check Link to comment https://forums.phpfreaks.com/topic/297779-searching-mysql-table-for-the-multiple-orders-by-the-same-person/#findComment-1518803 Share on other sites More sharing options...
CroNiX Posted August 14, 2015 Share Posted August 14, 2015 Looks like you could use array_values() there. Link to comment https://forums.phpfreaks.com/topic/297779-searching-mysql-table-for-the-multiple-orders-by-the-same-person/#findComment-1518804 Share on other sites More sharing options...
CroNiX Posted August 14, 2015 Share Posted August 14, 2015 but my array is not like array(1,2,3); it's like the following [0] => 3 [1] => 2 [2] => 1 You could also sort() the array to get them in (1,2,3) order. Link to comment https://forums.phpfreaks.com/topic/297779-searching-mysql-table-for-the-multiple-orders-by-the-same-person/#findComment-1518806 Share on other sites More sharing options...
Barand Posted August 14, 2015 Share Posted August 14, 2015 WHERE id IN (3,2,1) will give exactly the same results as WHERE id IN (1,2,3) Link to comment https://forums.phpfreaks.com/topic/297779-searching-mysql-table-for-the-multiple-orders-by-the-same-person/#findComment-1518807 Share on other sites More sharing options...
blmg2009 Posted August 14, 2015 Author Share Posted August 14, 2015 Thank you for your responses guys, I have solved the issue with the following: public function checkForMultipleOrders($post_code, $first_name, $last_name, $orders){ $orders = implode(',', $orders); $query = $this->db->query("SELECT `order_id` FROM " . DB_PREFIX . "order WHERE `order_id` IN(" . $orders . ") AND `shipping_postcode`='" . $post_code . "' AND `shipping_firstname`='" .$first_name . "' AND `shipping_lastname`='" . $last_name . "'"); return $query->num_rows; } Link to comment https://forums.phpfreaks.com/topic/297779-searching-mysql-table-for-the-multiple-orders-by-the-same-person/#findComment-1518811 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.