Jump to content

Torrie

Members
  • Posts

    20
  • Joined

  • Last visited

Torrie's Achievements

Member

Member (2/5)

0

Reputation

  1. ...Sigh... MacGyver, I wish I was smart enough to read your post and go "Oh I wish I thought of that," and then open up my code and type in a few lines and do what you just suggested. Unfortunately, I look at what you just said, and I'm thinking that is an Excellent idea.... but I don't know how to do what you just said. Would you be so kind as to post a couple lines of code? I know that I want my sales Invoice Number to start with the month and the date (e.g. I know that an Invoice Number that looks like "7108473" would go to an order created on July 10th, etc.). And my table is already autoincremented. Since I built the current code, I have 34 sales, so a "select max(id) as id from sales_orders" would give me "34" and not a number like "710****." If you could bang out 2 or 3 lines of code to push me in the right direction, I will absolutely PROMISE to hold a door open for an elderly lady this coming weekend.
  2. Quick question: how come you did it that way -- with the header: location next page, instead of the classic way of "<form action="nextpage.php"> I was always taught to use <form action="thepage_I_want.php">. Is this a newer, better way of doing things?
  3. Thank you, your answer gives me a lot to think about. In answer to the rand() question, $invoice_number.rand(1111,9999) just gives me the random number. Like you said, date("njis") gives a 6 - 8 character number, and the errors are easy to spot in my mySQL column: 7223564 7223669 7234452 11121 7234498 7238566 Here's my exact code: if (strlen($invoice_number) < 4) { $invoice_number = date("njis"); } ### INCREMENT invoice_number BY "1" IF the invoice_number ALREADY has been used before. $p1 = "select exists(select invoice_number from sales_orders where invoice_number regexp '".$invoice_number."' and name is NOT NULL and name NOT regexp '".$name."' )"; if (@mysql_result(@mysql_query($p1),0,0) == 1) { $orderarray = array(); $savedSQL = 'select invoice_number from sales_orders'; $savedQuery = mysql_query($savedSQL); while($savedResult=mysql_fetch_array($savedQuery)) { if(preg_match("/\d{4}/",$savedResult[0])) { $orderarray[] = preg_replace('/\D/','',$savedResult[0]); } } $invoice_number = (max($orderarray) + 1); } I cannot for the life of me think of what I can do to improve this code. Yes, it's newbie-stupid, and still uses deprecated mySQL, but I can't think of what else to do. The code (above) is in red, because my face is red/embarassed for the dumb question :-)
  4. 10-year intermittent problem: Invoices displayed on my website are assigned a unique 7-digit order number generated by PHP's date function $invoice_number = date("njis"); // creates, for example, invoice number "7223060" Roughly 10% of the time, no order number is displayed! That means, for whatever reason, from time to time, php's date function decides NOT to create a date. Over the past 10 years, I have been on different servers, at different hosts, with, obviously, different PHP versions. Is this one of those things, like, a "well-known-issue" about PHP's date function? Or what? I have even had to code built-in "backup-plan fail-safes" like: $invoice_number = date("njis"); if (strlen($invoice_number) < 4) { $invoice_number = date("njis").rand(11111,99999); // mail(webmaster notice); } What are your thoughts? Thank you!!
×
×
  • 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.