Re: FW: [PHP-DB] SELECT MAX(ID) PLUS 1

From: Date: Thu, 29 Mar 2001 15:14:10 +0000
Subject: Re: FW: [PHP-DB] SELECT MAX(ID) PLUS 1
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-7994@lists.php.net to get a copy of this message
Ma'am, I seem to have come late to this thread, and I think you've already chosen to go back to the multiple-table schema. I'm just posting to say that I think you made the right decision. If you have data that is structured in tree form, i.e. if you have something along the lines of
       *
      / \
      * *
       / \
       * *
      /
      *
and the number of levels is known ahead of time and can be a fixed part of the design, then you should use one table for each level in the hierarchy. (Even where the structure is more complicated that a tree structure, the principle still applies.) If I understand your description properly, this describes your web page design. One type of entity links to one or more other types of entity, which in turn link to one or more other types, on down the tree to a fixed depth. Relational databases were created to handle this type of information structure.
If your web page data is structured in this way, then the person who told you to use a single table either didn't understand your data structure, or doesn't understand database design. My experience is that when this principle is ignored, the project is in trouble. There's a limit to how much a programmer can do to solve problems caused by bad database design, as you have discovered. Bob Hall
Can anyone help me on this one Lisa -----Original Message----- From: Walter [mailto:walter@waltersworld.nl] Sent: Wednesday, March 28, 2001 10:55 AM To: Rubanowicz, Lisa Subject: Re: [PHP-DB] SELECT MAX(ID) PLUS 1 Are tables are to differnet, so you don't have anything on my code Sorry ----- Original Message ----- From: Rubanowicz, Lisa <mailto:lisa.rubanowicz@cnh.com> To: 'Walter' <mailto:walter@waltersworld.nl> ; Rubanowicz, Lisa <mailto:lisa.rubanowicz@cnh.com> Sent: Wednesday, March 28, 2001 10:57 AM Subject: RE: [PHP-DB] SELECT MAX(ID) PLUS 1 HI Walter, Could you please send me an excerpt of your code so I can see is my PHP syntax incorrect. Thanks Walter Lisa -----Original Message----- From: Walter [ mailto:walter@waltersworld.nl <mailto:walter@waltersworld.nl> ] Sent: Wednesday, March 28, 2001 10:09 AM To: Rubanowicz, Lisa Subject: Re: [PHP-DB] SELECT MAX(ID) PLUS 1 I think that your tables aren't good, my site have to menu's and submenu's but i don't have that problem ----- Original Message ----- From: Rubanowicz, Lisa <mailto:lisa.rubanowicz@cnh.com> To: 'Walter' <mailto:walter@waltersworld.nl> Sent: Wednesday, March 28, 2001 10:40 AM Subject: RE: [PHP-DB] SELECT MAX(ID) PLUS 1 I can't use auto_increment on two fields in the same table!! pg_id is auto_increment Lisa -----Original Message----- From: Walter [ mailto:walter@waltersworld.nl <mailto:walter@waltersworld.nl> ] Sent: Wednesday, March 28, 2001 9:42 AM To: Rubanowicz, Lisa Subject: Re: [PHP-DB] SELECT MAX(ID) PLUS 1 Why don't you use the auto_increment fucntion in MySQL self? ----- Original Message ----- From: Rubanowicz, Lisa <lisa.rubanowicz@cnh.com> To: <php-db@lists.php.net> Sent: Wednesday, March 28, 2001 10:17 AM Subject: [PHP-DB] SELECT MAX(ID) PLUS 1 Hi All, I have been driven maaaaaad with this now for about a week and have looked all around for the answer but seem to get sent off in a tangent any time I get close. My SELECT statement seems to be right when I run it in MySQLFront but to add 1 in PHP ......???? Here is the story. I have a small web site running from mySQL. Initially I had it all in different tables then an ASP colleague said I should do it it one table and use SELECT MAX(sub_id) etc. The site has obviously main navigation links Products, Freight Software, Small to Medium businesses and News etc. along the top of the site. But for each of the first three I want "Sub Links" (Products 1, Products 2, Products 3 etc) So I have a table like so pg_id (auto_increment) page_id (gives the type of page - one of the main six links) page_name sub_id (I need this to be 1, 2, 3 etc depending on how many pages they add to each section through a web form) sub_name (Clickable text for sub link) Of course there are many other fields (Title of page, Content of page, IMG for page etc) My problem is when I do a SELECT MAX(sub_id) AS sub_id_max WHERE page_id = $page_id I can't seem to get that figure in PHP and add 1 to it (increment). If I could do this, I would then do my INSERT INTO etc to add a new Sub Page for that section. I obviously can get the page_id in 'cause I am passing it over from the previous page. Can I do this or do I need to separate it out. I have redesigned the (very small) database 3 times now but the logic of it has me stumped. Ideally I would like to be able to keep it all in one table, but you guys know best. Could you please send me the four or five lines of code to do the above as it must be something with the SYNTAX Thanks in advance All the bEst Lisa Lisa Rubanowicz Case ITC, Navan, Ireland Tel: #353 (0)46 77663 lisa.rubanowicz@cnh.com < mailto:lisa.rubanowicz@cnh.com <mailto:lisa.rubanowicz@cnh.com> >
Know thyself? Absurd direction!
Bubbles bear no introspection.     -Khushhal Khan Khatak


« previous php.db (#7994) next »