Re: PHP+Mysql

From: Date: Fri, 17 Jan 2003 15:20:38 +0000
Subject: Re: PHP+Mysql
References: 1  Groups: php.general.es 
Request: Send a blank email to general-es+get-31361@lists.php.net to get a copy of this message
Julio, mysql mantiene el ultimo ID creado, por lo que al crear el 1, ese ya fue usado, asique el proximo sera 2, aun cuando vos cambies el 1 a 0 o borres el 1. Saludos, Pablo ----- Original Message ----- From: "Julio Herrera" <jherrera@chilered.com> To: <lista@phpes.com> Sent: Friday, January 17, 2003 11:14 AM Subject: [PHP-ES] PHP+Mysql > Cuando recien me inicie en php (aun me considero un principiante) encontre > un sitio donde salian varios articulos sobre php http://www.devshed.com.”áЋ¥ > a§Õ=h¡3 > Como estoy metido en comercio, entonces trate de seguir un tutorial para > crear un sitio de E-Commerce, el tutorial esta en > > http://www.devshed.com/Server_Side/PHP/Commerce/Commerce1/page1.html > el > problema se presento en una parte del tutorial donde aconseja cambiar la > numeracion de un campo INCREMENT de mysql, especificamente lo siguiente: > > Primero creamos un tabla de categorias de productos: > > mysql> /* create the categories table */ > -> CREATE TABLE categories ( > -> id int auto_increment not null, > -> parent_id int not null, > -> name varchar(25) not null, > -> description varchar(255) not null, > -> PRIMARY KEY (id), > -> INDEX parent_id (parent_id), > -> INDEX name (name) > -> ); > > luego insertamos un dato: > > mysql> INSERT INTO categories (id, parent_id, name, description) > -> VALUES (0, 0, 'Top', 'This is the top level category.') > > luego seleccionamos: > > mysql> SELECT * FROM categories; > +----+-----------+------+---------------------------------+ > | id | parent_id | name | description | > +----+-----------+------+---------------------------------+ > | 1 | 0 | Top | This is the top level category. | > +----+-----------+------+---------------------------------+ > > y esto sugiere el autor: > > Everything is in order here, or is it? Looking carefully we see that the ID > is 1 instead of 0 -- which is what we wanted it to be. What gives? This is > MySQL's autonumber, it automatically assigned the number 1. Normally this > would be okay, but we want our [Top] category to have the ID of 0 (just > because) so let's issue an UPDATE statement to fix this: > > mysql> UPDATE categories SET id = 0 WHERE id = 1; > > Now let's see it again: > mysql> SELECT * FROM categories; > +----+-----------+------+---------------------------------+ > | id | parent_id | name | description | > +----+-----------+------+---------------------------------+ > | 0 | 0 | Top | This is the top level category. | > +----+-----------+------+---------------------------------+ > > pero cuando yo recreo esto el segundo registro ingresado no empieza en 1 > sino en 2: > SELECT * FROM categories LIMIT 0, 30 > id parent_id name description > 0 0 Top This is the top level category. > 2 0 Fruits Fresh and tasty fruits. > > Hay algo malo aqui, el autor se equivoco o mi mysql funciona mal. > > Julio Herrera > > pd: Estuve revisando estos tutoriales para refrescar mi memoria

« previous php.general.es (#31361) next »