Re: PHP+Mysql

From: Date: Fri, 17 Jan 2003 15:58:20 +0000
Subject: Re: PHP+Mysql
References: 1  Groups: php.general.es 
Request: Send a blank email to general-es+get-31365@lists.php.net to get a copy of this message
Yo (desde mi poca idea inexperta), probaría a poner el insert con comillas, en lugar de 0. Yo lo hago así en los campos con autoincremento y no he tenido problemas. mysql> INSERT INTO categories (id, parent_id, name, description) -> VALUES ('', '', 'Top', 'This is the top level category.') ----- Original Message ----- --------------------------------- From: "Julio Herrera" <jherrera@chilered.com> To: <lista@phpes.com> Sent: Friday, January 17, 2003 5:14 PM 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. > 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 (#31365) next »