Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP]Jak zrobic numerowanie?
adi121
post
Post #1





Grupa: Zarejestrowani
Postów: 11
Pomógł: 0
Dołączył: 7.08.2013

Ostrzeżenie: (0%)
-----


Witam szukałem na forach i nie wiem jak zrobić numerowanie coś w stylu numerowania faktur czyli np:
10/P/09/2013 nastepny ma być numer 11/P/09/2013 i tak co nowy miesiąc to od nowa numeracjaczyli np dla pażdziernika 1/P/10/2013 potem 2/P/10/2013.

Za zadne skarby nie wiem jak to zrobić byl bym wdzieczny za pomoc. Albo jakąś podpowiedz

Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
markonix
post
Post #2





Grupa: Zarejestrowani
Postów: 2 707
Pomógł: 290
Dołączył: 16.12.2008
Skąd: Śląsk

Ostrzeżenie: (0%)
-----


Wycinek z mojej aplikacji. Może Cię naprowadzi.
$user->invoice_format to dowolny format ustawiany przez użytkownika (dzięki czemu można w przystępny sposób zmienić format numeracji).
Np. [number]-[month]-[year]

  1. $regexp = str_replace(array('[number]', '[month]', '[year]'), array('[[:digit:]]+', $currentMonth, $currentYear), $user->invoice_format);
  2. $sql = "SELECT `invoice_number` FROM $table_name [...] `invoice_number` REGEXP '^$regexp$' ORDER BY `id` DESC LIMIT 1";
  3. [...]
  4. if (!empty($result->invoice_number))
  5. {
  6. $regexp = str_replace(array('[number]', '[month]', '[year]'), array('(\\d*)', $currentMonth, $currentYear), str_replace('/', '\/', $user->$invoiceTypeFormat));
  7. preg_match('/^' . $regexp . '/', $result->invoice_number, $matches);
  8. $lastNumber = $matches[1];
  9. }
  10. else
  11. {
  12. $lastNumber = 0;
  13. }
  14. $newNumber = str_replace(array('[number]', '[month]', '[year]'), array($lastNumber + 1, $currentMonth, $currentYear), $user->$invoiceTypeFormat);
  15.  


Ten post edytował markonix 23.09.2013, 20:29:52
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 26.09.2025 - 09:06