Nov 21, 2009

Auto Increment Field - how to generate a field that increments since the last access

free web hosting
Open Discussion > MODERATED AREA > Computers > Programming Languages > PHP Programming

Auto Increment Field - how to generate a field that increments since the last access

villajay
Still learning php and mysql so hoefully this is an easy one. so the procedure goes as follows: user enters a new widget into the database, and the system automatically assigns an inventory number in the form ##-###. the first 2 numbers is the last 2 digits of the year, and the last 3 is a number that increments. auto-increment will not work since next year, it will have to start at 1. TIA!

Comment/Reply (w/o sign-up)

sonesay
So you wanted to have records of 08-001, 08-002, 08-001... and then 09-001, 09-002... ? If that is the case then you would need to use the date function in php to return the year (last two digits) and add it onto the -### part before inserting a new record. To get the -### part you would need to query and count the number of records for that year first and generate the next one appropriately. That is the simplest way I can think of doing it. Sorry I cannot provide any code at this time since I am working on something at the moment.

Comment/Reply (w/o sign-up)

jlhaslip
I would be tempted to do it differently than the above suggestion.

Use a full auto increment id for the entry, then a Date field for the year and then a combination Date-id field as the 'key' for the entry.

From past experience with a large Equipment Database, I suggest to you that having the "inventory number" be significant to the particular inventory item is not a good choice to make. Particularly if you attempt to limit the digits in an Inventory number. Trust me.
You are better off assigning the atomic parts and building up from there.
Example:
Database contains: Id, Group number, Category number, size, colour, date and other identifying information
Create another element in the Database to define the identifying number based on the sub-parts, ie: grp-cat-Id

Forcing an auto-incrementing number will cause havoc at some point. Auto-incrementing ID's are best left to the machine/software to deal with.

Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords :

  1. Xampp How Can I Generate "automatic Start Sites"
    (8)
  2. Ms-access Database Question
    Allowing Web Access to the Informaton (3)
    Hi. I wanna know if there is a way of accessing an MS-Access database so that my site can extract
    data from it and make it avilable online. I have an accounting package that saves everthing in an
    MDB file and I want that info available for my clients from whereever thay are. Split Topic ....
  3. Delete Problem With Id
    Id as auto_increment, and identifier for a row (4)
    Whenever I use 'delete from table where id = 4' from a table with several rows up to 10,
    the 4th row is removed and the update simply shows the rest from 1 to 10 without 4. This is not what
    I want. I want the table to now read 1 through 4 to 9 so that futher delete actions will be in that
    sequence. I want to identify my row with the id (number). Can anybody help out here. Very urgent.
    Serialmike.....
  4. Grabt Access To My Protected Files
    grabt access to my protected files (2)
    Hi all, I am sure all of you are great programers but First i am no code programmer i am just
    trying to learn to run my sites, will the problem is i got a code from the web to protect my files
    ,1st i want to know how to work it out then i will try other things but can't let it go without
    a fight thanx all php: CODE if ( ! defined( 'myname' ) ) {         print "You
    cannot access this file directly.";         exit(); } customer data here ?> now i
    can't access my files what is the method to access them all i want is to protect the f....
  5. Auto Pruning An Sql Database With Php
    How can i do this? (5)
    Hey all. Now i have a DB, an SQL DB, and i need to auto prune the data there to delete rows lder
    than a certain time, lets say 2 months for now, the question is how do i do this? The obvious thing
    is just to add a field which is the numerical representation of the month when the data is entered
    and every time the DB is accessed it will check this number against the current month,in a numerical
    format, and if the difference is two or greater that row is deleted, so if the month is January, it
    would be O1 and if the current month is march then it would be O3 and the diff....
  6. I Need Webmail On My Server
    (so admins on my site can access it) (0)
    Right now, if i go to the cpanel of my site, I can access webmail of any of the email addresses I
    have. Unfortunatly, I would prefer it if the administrators did not know the password to the
    cpanel. I want them to be able to access mail from 1 of the email accounts. I have tried letting
    all the admins access the account through their own cliants, but it became a mess, not knowing wich
    admins have responded to which emails, because most emails are hosted localy when received by
    cliants such as outlook. Then I had the idea of making one page, with webmail on it. Where....
  7. How To Access A Folder In Php Page
    (1)
    I have a folder on my hosting space..(i.e. public_html), i want to add this folder on my php page..,
    . how it should be done that, when i add some file in the folder using ftp or anything , the folder
    on that page automatically includes that file.for example , if the folder has 5 files..and on page
    it says "folder has 5 files" and shows the files...and when i have uploaded 2 more files ,it should
    automatically say that folder has 7 files.. ....
  8. Requesting Auto Generating Id Tag In Php Code
    Php Coding (3)
    Hello...I'm designing a website in PHP where ppl can submit their links for "cool sites".
    Anyway, when somebody submit's a link to a website for example "http://www.google.com" it
    creates an id such as "index.php?id=1134411593". I dont want the links to be converted into
    id's. I want it to remain as "http://www.google.com". I have the following coding on
    ( echo " ). I'm a novice. Please Help!!!! Thanks... Plus I
    also want to add the date on when the link was submitted. Please follow our forum rule by making....
  9. Suppressing Mysql Error In Php
    How to suppress auto generated mysql err (4)
    I am testing my website on my local machine. It is still in development stage and I am using
    php/mysql. If there is a mysql connection error, I am checking for the connection variable and
    displaying a proper error message. But even before it displays my error message, it displays an
    error message on browser thrown by mysql (MySQL Connection Failed: Access denied for user). Can I
    suppress this message and display only my message?....
  10. Restricting Page Access Using Php (need Help)
    (10)
    The code below is suppose to restrict access to pages without proper username and password.
    I've copied it word for word from a book I bought and I've tested it offline. I've
    already entered appropriate values in the database and nothing is wrong when I query. The problem
    is when I enter a wrong combination of username and password nothing happens when it should go back
    to index.html. Also when I correctly entered the username and password secretpage.php doesn't
    display anything. I'm guessing it has do with the setcookie function in login.php or ....
  11. Can Reset The Id Auto Increment?
    phpMyadmin (15)
    hi, Can we reset the id auto increment in the mysql database using by phpMyadmin? let's say the
    shoutbox . the id #number table.. somehow i deleted some rows.. and i wanted to re-order/reset the
    id number acendingly in order rather than skip out.. thks ....
  12. Increment A Mysql Column
    how to increment a MySQL column one unit (8)
    Hi, I have a column in a MySQL table which contains a counter of the views of the object described
    by this table. I would like to increment this value by one everytime the object is viewed. Obviously
    came into my mind the possibility of retrieving the value of this field, store it in a variable
    increment this value by one and perform an UPDATE query again with this new value. My question is if
    there is a MySQL option to update the field with its actual value plus an unit increment. I hope you
    understand the issue.....
  13. Php Classes
    Access the same class instance over multiple pages (1)
    Hey everyone. I am having some trouble accessing the same php class instance in more that one page.
    This is for my login script and what i need to do is be able to call the classes logout function
    from a separate page. What i have tried to do is create a new .php page and include the class file
    and then make a new class and call logout. This does not work because it does not log out the
    current user which is my problem. Can anyone help me fix this or know of another way to do it?
    Below is my class file CODE     // member class     // handlers member logon     cl....
  14. Generate Random Phrases
    ...from a txt file (4)
    I have a question on how to generate random phrases (facts, quotes, etc) which the server will
    randomly pick from txt file. Normally, I would use SSI to accomplish this task, but I recently added
    a blog (Nucleus) to my site which uses PHP (.php file). So my question is, how can you display
    random phrases in which the server will pick from a specified text file? Thanks! I saw a thread
    very similar to my problem, but the code supplied by Inspired does not allow the server to select
    the phrase from a file. The only reason I want this is because I have over 100 quotes,....
  15. About Set Permisstions....
    auto set it, how? (4)
    I have some problem about set permissions by automatic.. for example... I created txt file with
    php... but when my file was added to server(trap17), it always set to 644 and i want to set it to
    666 . Anybody help me... PLEASE /biggrin.gif" style="vertical-align:middle" emoid=":D" border="0"
    alt="biggrin.gif" />....

    1. Looking for Auto, Increment, Field

Searching Video's for Auto, Increment, Field
See Also,
advertisement


Auto Increment Field - how to generate a field that increments since the last access

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com