Jump to content

TheBrandon

Members
  • Posts

    72
  • Joined

  • Last visited

    Never

Everything posted by TheBrandon

  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.
  16. Right now I have an array of zipcodes with open invitations; I want to loop over the array of zipcodes, query the database and get the name of each zipcode and then remove duplicate names. So if 90210, 90211 and 90212 are in the array with the first 2 being City A and the last one being City B, I just want City A and City B, not City A, City A, City B. Right now I'm doing this: foreach($invitation_Zipcodes as $key => $value){ echo 'Key: '.$key.' Value: '.$value.'<br/>'; $csaname_sql = "SELECT CBSA_Name FROM ZIPCodes WHERE ZipCode = '$value'"; $csaname_result = mysql_query($csaname_sql); $csaname_array[] = mysql_fetch_assoc($csaname_result); } //$csaname_array = array_unique($csaname_array); print_r($csaname_array); echo '<hr/>'; print_r($invitation_Zipcodes); exit; That outputs this: If I uncomment the unique call, it outputs this: What am I doing wrong? Why is it losing "Pensacola-Ferry Pass-Brent, FL" ?
  17. Fantastic. Assigning it as an array first totally fixed it. Thank you all for your help. Maybe a noob question but I honestly thought all $_SESSION values were by default arrays? Also on that note, AyKay47, would you mind telling me the ideal alternative to passing the errors through the session? They have to be carried from one PHP file to another; would the alternative be logging IP session keys with error messages in the database then simply removing them once they are displayed?
  18. Forgot to mention, it's giving me the error: <b>Fatal error</b>: [] operator not supported for strings in <b>/edit_Contact_Info_Process.controllers.php</b> on line <b>134</b><br />
  19. Hello all, I have an error handler that I need to append messages to (First name not right, Last name not right, etc) I'm using a session array to handle all error messages titled GORB. How come this code won't work? $_SESSION['GORB']['message'][] = "First name wrong"; $_SESSION['GORB']['message'][] = "Last name wrong"; How can I get it to work? I already have the handler output written and functioning fine, I just need to get it to loop over an array of errors instead of just one.
  20. I got it working. Thank you very much, everyone. The problem was the $k['title'] in this example. Needs to be $v['title']. Works beautifully. Thanks again everyone.
  21. Thank you for the help. I'm having some trouble implementing it with my code. Can you please let me know where I'm going wrong? Do I need to modify my output somehow? It seems right to me as long as we are overwriting the $array array with the sorted version. //get the xml id from the url $xml_id = $_GET['xml_id']; //get the actual xml filename using our $_XML array assigned in config $xml_filename = $_XML[$xml_id]; //convert the xml to an array $array = xml2array(file_get_contents(''.$_CONFIG['site_url'].'xml/'.$xml_filename.'')); foreach($array['query']['row'] as $k=>$v) { $sort[] = $k['title']; } array_multisort($sort, SORT_ASC, $array['query']['row']); //echo '<pre>' . print_r($array,true) . '</pre>'; switch ($XML_File){ case "1": $sub_type = $accomodations_subcat[$_GET['cat_id']]; echo '<ul>'; foreach ($array['query']['row'] as $key => $value) { if($value['subtype'] == $sub_type && $value['active'] == 1){ echo '<li><a href="index.php?xml_id='.$_GET['xml_id'].'&cat_id='.$_GET['cat_id'].'&listing_id='.$key.'">'.$value['title'].'</a></li>'; } } echo '</ul>'; break;
  22. Yeah I tried that but I don't think I could figure out the syntax. Is there anyway you could show me an example using the array syntax above?
  23. Hello all, I have a rather large array and I need to list it's contents in an alphabetical list. The array is built like this: $array['query']['row']['0']['title'] = 'Bob'; $array['query']['row']['1']['title'] = 'Andy'; $array['query']['row']['2']['title'] = 'Tom'; I need to sort it so it is in alphabetical order based on the title. Is there an easy way to do this?
  24. Okay so I tried using your BCC header on my code and it didn't do anything differently, so now I'm trying that tutorial you posted. I'm using this code, but again, the bcc does nothing. I'd appreciate your help. <?php //define the receiver of the email $to = 'brandon@revivemediaservices.com'; //define the subject of the email $subject = 'Test HTML email'; //create a boundary string. It must be unique //so we use the MD5 algorithm to generate a random hash $random_hash = md5(date('r', time())); //define the headers we want passed. Note that they are separated with \r\n $headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com"; //add bcc header $header .= "\r\nBcc:brandon@revivemediaservices.com, brandon@revivemediaservices.com, michele@revivemediaservices.com"; //add boundary string and mime type specification $headers .= "\r\nContent-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\""; //define the body of the message. ob_start(); //Turn on output buffering ?> --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit I'm the announcement variable too! Yay! --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: 7bit <html> <head> <title>New Announcement</title> <style> table {background-color:white;border:1px solid black;padding:5px;} table tr {padding:10px;border:1px solid black;background-color:white;} table tr td {padding:5px;border:1px solid black;} table tr.odd {background-color:#e2e1df;} </style> </head> <body> <table> <tr> <td><p>Please see below for a new announcement</p></td> </tr> <tr> <td>I'll be an announcement variable one day!</td> </tr> </table> </body> --PHP-alt-<?php echo $random_hash; ?>-- <? //copy current buffer contents into $message variable and delete current output buffer $message = ob_get_clean(); //send the email $mail_sent = @mail( $to, $subject, $message, $headers ); //if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" echo $mail_sent ? "Mail sent" : "Mail failed"; ?>
  25. OSX. Yeah I noticed the \r\n thing earlier and tried this, but it didn't work: $subject = 'New Announcement From Rhino Shield'; $headers = "From: ".$to." \r\n"; $headers .='Content-type: text/html; charset=iso-8859-1 '. "\r\n"; $headers .= 'BCC: '.$email_array.'' . "\r\n"; I'll take a look at the article when I get home. Thank you for recommending it. I don't intend to try and make poor code to scrape by; it's more of an intellectual curiosity side of things as to why simply adding BCC breaks it.
×
×
  • 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.