Jump to content

Searching mysql table for the multiple orders by the same person.


blmg2009

Recommended Posts

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 :)  

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] => 1

Which I'm struggling to find the correct way to check 

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;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.