Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Jan 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Auto generate the number an display in php page

    when i click register page to enter the student information,I want student id to auto generate and display in the register page so that i don't have to add student id manually like other information(name, gender, course ...etc)

    I am very new to this forum ..i would be grateful if all you could help me.

    cheers

  • #2
    Regular Coder
    Join Date
    Mar 2006
    Posts
    200
    Thanks
    27
    Thanked 2 Times in 2 Posts
    Hello,

    Are you using a mySQL database to store the information? If so, you can set the student id field to auto increment (that means it automatically increments the student id field for you as you add entries).

    Then on your webpage, you'd post all the information you want to add for the student e.g. name, gender etc and add it to the database, but when you do, don't add any value for the student_id field e.g.

    Code:
    $insert = mysql_query("INSERT into students (student_id, name, gender, course) values ('NULL', 'Sarah', 'female', 'Computer Science')")
    Hope this helps!

    Nicky

  • #3
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Just a small addition to what nickyfraggle said-- assuming you are using MySQL and an auto-increment ID column, you can retrieve the ID that was just inserted using the PHP function mysql_insert_id().

    http://us2.php.net/manual/en/functio...-insert-id.php

  • #4
    Regular Coder
    Join Date
    Mar 2006
    Posts
    200
    Thanks
    27
    Thanked 2 Times in 2 Posts
    Hey I haven't heard of that one...I'll go do some reading...Thanks!

  • #5
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Its quite a useful function. May take you a couple tries to get used to it. Just depends on how complex your coding is.

  • #6
    Regular Coder
    Join Date
    Mar 2006
    Posts
    200
    Thanks
    27
    Thanked 2 Times in 2 Posts
    Hehe probably not very complicated - I studied Java at uni and have been teaching myself php for a couple of years now, but my whole approach to programming is fairly clean and simple - tutors used to like my code because it was really simple to find out what was going on...it was basic and broken into chunks or my lil brain can't handle it :-)

    I've had a go at this function and it's worked a treat...yay!

    Thanks!

  • #7
    New to the CF scene
    Join Date
    Feb 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Auto generated number

    Heloo,

    I'm using my sql db to store information.
    my problem is how to display an auto generate field in php page?

    my problem same with onam143. every time i click on new file, file id will auto generated. file id will appear in the new form shows what number the file is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •