Jump to content

TheBrandon

Members
  • Posts

    72
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Male

TheBrandon's Achievements

Member

Member (2/5)

0

Reputation

  1. 2012-04-17 14:26:35 is greater than "2011-04-19 00:00:00" Yep. I'm retarded. That's what the issue was. Thank you. Got it working.
  2. I'm sorry, the second one was changed to: SELECT * FROM orders WHERE orders_date_purchased < "2011-04-19 00:00:00"
  3. Hello all, I need to pull all of the records in MySQL since a certain date. I have my dates stored in MySQL in SQL's timestamp format. I thought a query like: SELECT * FROM orders WHERE orders_date_purchased > "2011-04-19 00:00:00" Would do it but so far it's not. That is returning "2012-04-17 14:26:35" which should be outside of the range I want. If I change the direction to: SELECT * FROM orders WHERE orders_date_purchased > "2011-04-19 00:00:00" The only thing it returns is 0000-00-00 00:00:00. This seems horribly simple and maybe the coffee just hasn't kicked in yet but I can't figure it out. Anyone have any ideas?
  4. I got it. I put it inside of a loop using array_key_exists. If anyone has a better method, I'd love to know! foreach($existing_Array as $key => $value){ if(!array_key_exists($key, $submitted_Array)){ $new_Array[] = $key; } }
  5. Hello all, I have 2 arrays containing numbers; I just need to extract the unique ones from the first array. For example, right now I have this: I want this: I thought array_diff did this exactly, but when I do: $new_Array = array_diff($existing_Array, $submitted_Array); It's giving me this: Can someone help me get this to work?
  6. Wow, I didn't realize that lol. Thank you very much. Sometimes I guess you just need another mind looking at the problem! Have a great day, thanks again!
  7. Hello all, I have a typical registration system where users can create accounts and the current time is stored in a TIMESTAMP field. I need to calculate how many people joined with the last 40 business days. What is the best way to achieve this? I found a few functions on php.net for calculating business days but all of the ones I found seem to deal primarily with the future, not the past. I really just need the single date. If I could just get a function that would return a 2012-05-24 21:11:49 type timestamp for the date 40 business days ago, I think I could take it from there, I'm just not sure what the most efficient way to calculate this is. Any ideas?
  8. Oh okay, the first one is similar to what I was doing. I'll look into str_repeat, thanks a lot! =)
  9. implode alone is capable of that? Could you show me an example of how to achieve this using implode? I've been trying to do it with a foreach loop.
  10. Hello all, I'm trying to get better at manipulating arrays and I'm stumped on this one. What would be the most efficient way of converting an array such as this: Into this:
  11. Can you elaborate on how to do this or link me to a more detailed tutorial on how to achieve this? I've never used the ON DUPLICATE KEY UPDATE clause. So it can take an array of say, 3 "new" inserts to the database and 2 "update" queries and do them both in one query? This would certainly be a tremendous time saver for me to learn. I looked into the mysql website site here: http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html and read a few examples I found but I really am having trouble taking the example and applying it concept wise to what I want to do. Would you mind helping explain it a little further in relation to what I'm trying to do so I can learn it?
  12. Hello everyone, I'm currently working on a large inventory management screen; the website has multiple "distributors" with their own inventory of products. Each distributor has the potential to carry the entire catalog of SKU's so right now, I have the stock/sku/dealer ID/product ID in one table with the product data/ID in another and am only inserting new rows if they are carrying the product. However they want to manage all of the inventory at once so I need to determine which IDs are update queries and which are insert queries. I'm trying to achieve this by comparing an array of the submitted data against an array of their existing inventory. If they don't have an entry for the submitted data key, we need to insert a new row for it to track their inventory. I just can't figure out how to get the keys to line up. Here is what I have; I tried to put it all into obviously defined variables for this forum. // assign our submitted values to an array $submitted_data = $_POST; // remove the SKUs with 0 or no inventory submitted $submitted_data = array_filter($submitted_data); // pull the distributor id out of the array before the insertion loop $distributors_inventory_distributor_ID = array_pop($submitted_data); // pull all existing inventory for this distributor to see if we are adding new inventory // or updating old inventory $existing_Inventory_Result = mysql_query("SELECT distributors_inventory_product_ID FROM distributors_inventory WHERE distributors_inventory_distributor_ID = $distributors_inventory_distributor_ID ORDER BY distributors_inventory_product_ID ASC", $db); // verify there is a result $existing_Inventory_num_results = mysql_num_rows($existing_Inventory_Result); if ($existing_Inventory_num_results > 0){ while($existing_Inventory_row = mysql_fetch_assoc($existing_Inventory_Result)){ // put existing inventory into an array $existing_Inventory[] = $existing_Inventory_row['distributors_inventory_product_ID']; } } $update_Inventory_Array = array_diff($submitted_data, $existing_Inventory); // print the array [DEBUG ONLY] echo '<h1>$update_Inventory_Array:</h1>'; print_r($update_Inventory_Array); echo '<hr/>'; echo '<h1>$submitted_data:</h1>'; print_r($submitted_data); echo '<hr/>'; echo '<h1>$existing_Inventory:</h1>'; print_r($existing_Inventory); That is outputting this: I'd like it to be: Can anyone suggest how to do this? I think if I could make the existing_Inventory array line up with my submitted_data array I could sort the rest out but I'm not sure how to get the keys/data to line up properly.
  13. Thank you so much for your in-depth reply. I definitely understand what you're saying. I didn't realize array_unique was solely meant for single-dimension arrays. Thanks again!
  14. Could you elaborate on how to just pull the CBSA_Name value? I'm still learning a lot when it comes to manipulating arrays so I think this is something I do frequently and would like to know how to do properly.
  15. I'll definitely try the solutions you have recommended. Thanks both of you. In an effort to further understand how the array_unique command works, could you still tell me why that wasn't working the way I wanted? I fully intend to switch to your SQL version of the code, I'd just like to learn why it didn't work for future projects.
×
×
  • 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.