Re: Getting last row / auto_increment..
| From: | scottrus at ipass dot net | Date: | Mon, 03 Jul 2000 05:49:18 +0000 |
| Subject: | Re: Getting last row / auto_increment.. | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-832@lists.php.net to get a copy of this message | ||
Not 100% if it will work so I suggest you run some test queries
in mysql before (which is what I assume you are using)
Try using greatest (or max in earlier versions of mysql)
to select the greatest value from the ID field. You can then
increment the id in php however you like and include the incremented
id in the sql insert.
You should make sure your ID field is set to be unique in the
database to prevent any possible errors of duplicate ids.
Info on GREATEST can be found at
http://www.mysql.com/documentation/mysql/commented/manual.php?section=Mathematical_functions
-- Hope this helps.
On Mon, Jul 03, 2000 at 09:26:07AM -0400, Chad Day wrote:
> I have a database where the ID field is in the form XXYYYY, where XX is a
> couple of letters, and YYYY is a numerical value, which needs to increment
> by 1 for each entry. Since there is text being used in this field, I can't
> make it auto_increment.. what would be the best way to handle this then?
> How can I grab the last value? All I can think of is cutting off the YYYY
> using substr, then adding 1 to the YYYY value. I need to know how to get
> the last row in the table though first.. of course there might be an easier
> way too, so any advice would be appreciated :)
>
> Chad Day
> Beach Associates
>
> When I speak german... I think german in my head... but like...Do skript
> kiddies see a w40l3 8uncha 1's and 0's and 3's and 4's and 7's in
> their
> h34d'5 w43n t43y R +a1k1n6 ? -- SirStanley
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net
> For additional commands, e-mail: php-db-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
--
Scott