Jump to content

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


Go to solution Solved by 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 

 

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.

Edited by CroNiX
  • Like 1
  • Solution

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;
}
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.