Jump to content

ajhanna88

Members
  • Posts

    11
  • Joined

  • Last visited

ajhanna88's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I agree, I have made an attempt however it's not a great one. i don't expect to be given the answer just some advice to get me going on the right lines. Thanks //loop through each product in order foreach ($stockrequired as $id) { //loop through all items in stock foreach ($instock as $key => $value) { //here I want to match the "product ids that are the same in both arrays while ($id == $value) { //while stock required id is equal to instock id } } }
  2. I have tested your code and it works fine for me, I would check to make sure that username and password variables are getting set e.g. if(isset($_POST['username'])){ $username = $_POST['username']; }
  3. remove the semicolon from the end of this line if ($username == '12345' and $password == '12345');
  4. Thanks, that worked the final part of my puzzle is now compare the below array product ids Array ( [35659] => 1 [35699] => 1 [35735] => 2 ) to this one, I want to loop through until each product id has been matched in the second array. Array ( [9] => Array ( [35659] => 35659 [35699] => 35699 [35735] => 35735 ) [126] => Array ( [35659] => 35659 [35699] => 35699 ) [114] => Array ( [35659] => 35659 ) ) what i am trying to produce is just this [9] => Array ( [35659] => 35659 [35699] => 35699 [35735] => 35735 ) Thanks
  5. awesome that worked thanks. I now want to group this array: Array ( [35659] => 9 [35659] => 114 [35659] => 9 [35699] => 126 [35735] => 9 ) into Array ( [9] => Array ( [35659] [35659] [35735] ) [114] = > Array ( [35659] ) [126] = > Array ( [35699] ) ) e.g. group by warehouse that contains the most products? Thanks
  6. I'm still pretty new to php and have an issue i'm trying to solve, I have the following two arrays The first one is contains product id's and the quantity ordered Array ( [35659] => 1 [35699] => 1 [35735] => 2 ) The second one contains warehouse locations that stock the product and the quantity they have available Array ( [35659] => Array ( [9] => 10 [114] => 1 [126] => 0 ) [35699] => Array ( [9] => 8 [114] => 0 [126] => 5 ) [35735] => Array ( [9] => 10 [114] => 0 [126] => 0 ) ) So what I am trying to do is loop through and add to an array each warehouse that meets the quantity of the order here is my code: $stockrequired = array('35659' => '1', '35699' => '1', '35735' => '2'); $instock = array(); foreach ($locations as $location) { foreach($stockrequired as $id => $qty){ if($stockavailable[$id][$location] >= $qty){ $instock[$id] = $location; } } } print_r($instock); However this produces the following which is the last warehouse that meets the quantity. Array ( [35659] => 114 [35699] => 126 [35735] => 9 ) What I need is all the warehouses the meet the quantity for each product e.g. my desired outcome will be below. I'm guessing my loop is getting reset or something? Any help would be appreciated. Array ( [35659] => 9 [35659] => 114 [35659] => 9 [35699] => 126 [35735] => 9 )
  7. Hi guys, I am trying to use a function that accepts two parameters the name (id of the div) and the video file path (filename) to avoid duplicating code 5 times for each video which does the exact same thing, however it is not loading the video. I have checked my error console on firebug and I am receiving no errors on the page, is what I am trying to achieve possible, or am I calling the code in the wrong place? Thanks <script> $(document).ready(function(){ playVideo('video_01', '/video/video1.mp4'); playVideo('video_02', '/video/video2.mp4'); playVideo('video_03', '/video/video3.mp4'); playVideo('video_04', '/video/video4.mp4'); playVideo('video_05', '/video/video5.mp4'); function playVideo(name, filename) { jwplayer(name).setup({ file: filename, controls: true, width: 680, height: 498, autostart: false, //repeat: "always", stretching:"fill", backcolor: 'FFFFFF', smoothing: 'false', startparam: 0, events: { onPause: function(event) { jwplayer(name).play(); }, onSeek: function(event) { jwplayer(name).play(); } } }); $(window).resize(function(){ var vidsizes = getEraVidSizes(); jwplayer().resize(vidsizes.width,vidsizes.height); }); } }); </script>
  8. Ok so I have managed to loop through and check each warehouse individually for where products meet the quanitity required. I am now left with the following two arrays: The first being their order: Array ( [35659] => 1 [35699] => 1 [35734] => 2 ) And the second being each warehouse that has the quantity of the product available Array ( [9] => Array ( [35659] => 1 [35699] => 1 [35734] => 2 ) [114] => Array ( [35659] => 1 ) [126] => Array ( [35699] => 1 ) ) What I now need to do is to compare the first array (product id) to the second array (product id) for each warehouse indivual warehouse to see the differences. I have been playing about with array_diff but haven't been able to get it yet. Thanks
  9. Thanks, I'll give that a try and report back and yes it makes complete sense to rearrange into warehouse and the products they contain.
  10. Thanks for the reply, that makes sense dealing with an array of warehouses. Would you be able to give some advice on how i would achieve the steps that I have bolded above in php? thanks
  11. Hi there i have recently started working with php so I will probably be a familiar name around here. I have been giving a task that I have got a bit stuck with. To give a brief overview I have products that are stocked in x number of warehouses, when a customer places an order depending on their location I will ship from the warehouse that is closest to them if it has all products in stock. I have the following two arrays The first represents a customers order containing the id of the product and the quantity they have selected. e.g. product id:35659, qty:1 Array ( [35659] => 1 [35699] => 1 [35734] => 2 ) The second array shows the quantity in stock for each product in each 3 warehouses that stock it e.g. 35659 being the product id, [9][114][126] being the warehouse and 10,1,0 being the quantity of stock for that item in the warehouse. Array ( [35659] => Array ( [9] => 10 [114] => 1 [126] => 0 ) [35699] => Array ( [9] => 8 [114] => 0 [126] => 5 ) [35734] => Array ( [9] => 10 [114] => 0 [126] => 0 ) ) function check_warehouse_stock($order=array(), $stock=array(), $warehouse=0) { foreach($order as $id => $qty) if($stock[$id][$warehouse] < $qty) return false; return true; } // $warehouses is an array of my warehouses already in their preference order foreach($warehouses as $w) { if(check_warehouse_stock($order, $stock, $w)) break; $w = false; } // $w is now the first warehouse with all the stock, or false if no warehouses have any stock So far I have got the above code which loops through each warehouse and goes into a function that checks each item in their order and sees if any item in their basket is below the quantity in the warehouse, if no items is below the quantity it returns true and that is the first warehouse with all items in stock, if no warehouse has all items in stock it returns false. This is where I am getting stuck, if no warehouse has all items in stock I need to go into a similar function and have some sort of rule that checks if no one warehouse has all products in stock I will ship from wherever has each product in stock starting with the closest and so on... e.g. if the first warehouse had 2 of the 3 items in stock and the second warehouse had 1 in stock we would ship 2 products from the first and 1 from the second. Any help would be greatly appreciated, even with just the logic on how to approach this. Thanks
×
×
  • 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.