+ Post New Thread
Results 1 to 6 of 6
How do you do....it? Thread, SQL in Technical; we have a logging system that logs all the hardware and equipment we have and one section of it is ...
  1. #1

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    10,053
    Thank Post
    3,585
    Thanked 1,123 Times in 1,025 Posts
    Rep Power
    377

    SQL

    we have a logging system that logs all the hardware and equipment we have and one section of it is where I have to go around and check the lapsafes around the school.

    Anyway to cut a long story short In the database I have to manually alter each laptop item in the database to physically change the date to the date that I did the check ( which is a long winded process )

    Is there anyway I could have a button on the web front end so that it altered the date for the selected items.

    Selected items are items that are checked using a check box so that when I click the button it changes the date to todays date ( that does not change )

    ie

    laptop 1 checkbox1 06-february-2008
    laptop 2 checkbox2 06-february-2008
    laptop 3 checkbox3 06-february-2008
    etc
    etc

    Alter date <-- click this button so that it puts the above dates in the date column to 06-february-2008

    so that it does not link to the system clock so that when I come back tommorow or any time after today the date is still 06-february-2008

    and not 07-february-2008 or greater then that ?

  2. #2
    Jona's Avatar
    Join Date
    May 2007
    Location
    Cranleigh
    Posts
    471
    Thank Post
    14
    Thanked 51 Times in 49 Posts
    Rep Power
    24
    The SQL command you want is something like
    UPDATE laptoptable
    WHERE [laptopid]=laptop
    SET [date]='06/02/2008';

    ref: http://www.w3schools.com/sql/sql_update.asp

    but with out knowing more details, I can't really help any more (table name, schema, sql server type, client language, etc).

    Cheers
    Jona

  3. #3
    JohnCondon's Avatar
    Join Date
    Apr 2007
    Location
    Bromcom
    Posts
    283
    Thank Post
    48
    Thanked 65 Times in 42 Posts
    Rep Power
    27
    If you substitute the date in the above example with GetDate() it would use todays date rather than having to manually edit the date value each time or if you want it to always show the particular date use the above as written.
    There are a whole slew of Date parameter variables (exact syntax depends on version of SQL your using) that should allow you to get exactly what date format you want too.

  4. #4
    Jona's Avatar
    Join Date
    May 2007
    Location
    Cranleigh
    Posts
    471
    Thank Post
    14
    Thanked 51 Times in 49 Posts
    Rep Power
    24
    Quote Originally Posted by JohnCondon View Post
    If you substitute the date in the above example with GetDate() it would use todays date rather than having to manually edit the date value each time or if you want it to always show the particular date use the above as written.
    There are a whole slew of Date parameter variables (exact syntax depends on version of SQL your using) that should allow you to get exactly what date format you want too.
    getDate works in MSSQL, the my-sql equivlent seems to be curdate(). http://dev.mysql.com/doc/refman/5.0/...functions.html.

    But if your doing it from a front-end it maybe easier to use that to generate the current date.

    To address another point of the OPs, once you write it to the database, it won't automatically update to the system clock so you shouldn't have to worry about that.

  5. #5

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    10,053
    Thank Post
    3,585
    Thanked 1,123 Times in 1,025 Posts
    Rep Power
    377
    so going from the above info if i used :

    Code:
    UPDATE laptoptable
    WHERE [laptopid]=laptop
    SET [date]=curdate();
    Is that the correct syntax

    assuming that latoptable is the name of the table and where does each [laptopid] come from ?

    also what is laptop ?

    taking into consideration that for example in one lapsafe in the database it pulls up the laptops from the science lapsafe, this has 16 laptops in it.

    So there will be 16 check boxes ( each check box on the same line as each laptop )

    laptop one -- [c]
    laptop two -- [c]

    etc

    where [c] is a physical checkbox where I click the mouse and it checks or unchecks the checkbox.

    Thanks

  6. #6
    Jona's Avatar
    Join Date
    May 2007
    Location
    Cranleigh
    Posts
    471
    Thank Post
    14
    Thanked 51 Times in 49 Posts
    Rep Power
    24
    This is all getting rather abstract but in my example laptop was the id of the database record about the laptop I suppose really it should have been in quotes ''.

    [laptopid] would be the unique identifer (primary key) field of the laptop record in the table laptoptable.

    Talking about checkboxes isn't that helpful as you need to know what's going on in the underlying database. A checkbox could imply a boolean field so it would be something like
    update ...... SET [booleanFieldThatIsSourceOfCheckbox]='True';

    But you've mentioned date so I think you need to take a look at the underlying database tables. If you look at the state of a specific record first then do the check box and see how the record changes that should give you a good start.

    Cheers
    Jona



SHARE:
+ Post New Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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