php-db | 2005011
Date: 01/06/05
- Next message: James Pancoast: "Re: [PHP-DB] Trying to connext to MySQL with PEAR"
- Previous message: Andrew Kreps: "Re: [PHP-DB] PHP connect to mysql problem"
- In reply to: John Holmes: "Re: [PHP-DB] MySQL Auto PK"
- Next in thread: Jason Wong: "Re: [PHP-DB] MySQL Auto PK"
- Reply: Jason Wong: "Re: [PHP-DB] MySQL Auto PK"
- Reply: Jochem Maas: "Re: [PHP-DB] MySQL Auto PK"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Wed, 05 Jan 2005 18:11:23 -0500, John Holmes
<holmes072000 <email protected>> wrote:
> OOzy Pal wrote:
> > Is it possible to have mysql at an ID as 20050105-1 as
> > (YYYYMMDD-1), -2, etc.
>
> automatically? No. But you can always just use
>
> SELECT CONCAT(date_column,'-',pk_column) AS fixed_id ...
>
> if you _really_ need something like this. Or just join them together in
> PHP.
I think the only downside to that solution is that the primary key
will continue to increment regardless of the day, and I think the
original poster wanted:
20050105-1
20050105-2
20050106-1
...etc.
This would be a great place for a stored procedure, but I don't know
if I can recommend running MySQL 5 to you. The most platform-safe way
I can think of is to get a count(*) of the number of rows with today's
date, add 1 to it, and stick that number on the end of the string
you've created to insert into a varchar field. It's an extra query
per insert, but it'd do the job.
-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
- Next message: James Pancoast: "Re: [PHP-DB] Trying to connext to MySQL with PEAR"
- Previous message: Andrew Kreps: "Re: [PHP-DB] PHP connect to mysql problem"
- In reply to: John Holmes: "Re: [PHP-DB] MySQL Auto PK"
- Next in thread: Jason Wong: "Re: [PHP-DB] MySQL Auto PK"
- Reply: Jason Wong: "Re: [PHP-DB] MySQL Auto PK"
- Reply: Jochem Maas: "Re: [PHP-DB] MySQL Auto PK"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

