Fw: [PHP] doing auto number myself to a primary key...
| From: | Kevin Stone | Date: | Fri, 31 Jan 2003 21:53:04 +0000 |
| Subject: | Fw: [PHP] doing auto number myself to a primary key... | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-133828@lists.php.net to get a copy of this message | ||
In MySQL you use MAX() to retrieve the maximum value from a column.
SELECT MAX(id) as id FROM divxtemp
-Kevin
----- Original Message -----
From: "Mr. BuNgL3" <mrbungle@netcabo.pt>
To: <php-general@lists.php.net>
Sent: Friday, January 31, 2003 2:31 PM
Subject: [PHP] doing auto number myself to a primary key...
> $sql="SELECT TOP(id) FROM divxtemp";
> $res=mysql_db_query("DB",$sql) or die (mysql_error());
> $reg=mysql_fetch_array($res);
> $id=$reg["id"]+1;
> $sql="INSERT INTO divxtemp (titulo,cds,id) VALUES
> ('$titulotxt','$cdstxt','$id')";
> mysql_db_query("DB",$sql) or die (mysql_error());
>
> the id is always 1 so he can't save duplicate keys...
>
> what i'm doing wrong? : \
>
> thanks...
>
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>