1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: MySql and phpMyAdmin query

Discussion in 'Web Design & Development' started by JiminSA, Jul 13, 2012.

Thread Status:
Not open for further replies.
Advertisement
  1. allnodcoms

    allnodcoms

    Joined:
    Jun 30, 2007
    Messages:
    613
    Not with you mate, what are you trying to do?

    If you can give me an example I'm sure we can work it out...

    Danny
     
  2. JiminSA

    JiminSA Thread Starter

    Joined:
    Dec 15, 2011
    Messages:
    2,058
    When a vehicle in the database has been edited, I would like it to reflect in the record - i.e. by which user and at what time - by including 2 fields "agent" and "date_time", one occurrence for each time it's edited - which can happen n times i.e. a variable number of occurrences in the life of the record.

    If SQL can handle that scenario, I'd love to know...
     
  3. allnodcoms

    allnodcoms

    Joined:
    Jun 30, 2007
    Messages:
    613
    It can James, welcome to the world of database design.

    I'd have a separate table called 'edits' or similar, this table has the name and timestamp, maybe a reason for the edit (?) and a reference to the main vehicle table that it refers to. Whenever the vehicle table is edited, you just create a new 'edits' entry and set the pointer to the vehicle entry's id.

    Easy peasy!

    Danny
     
  4. JiminSA

    JiminSA Thread Starter

    Joined:
    Dec 15, 2011
    Messages:
    2,058
    That can work! ;)
    All I need to do is SELECT * FROM editing_table WHERE recid = $row['id'] ORDER BY datestamp
    or summat like that...
    Then there are no limits on the number of edit transactions! - I like the way you roll Danny! :D
     
  5. allnodcoms

    allnodcoms

    Joined:
    Jun 30, 2007
    Messages:
    613
    It's easy when you know how mate... ;)

    Danny
     
  6. JiminSA

    JiminSA Thread Starter

    Joined:
    Dec 15, 2011
    Messages:
    2,058
    Danny, is there anything to stop me serialising an array into a row and then un-serialising it?:rolleyes:
     
  7. allnodcoms

    allnodcoms

    Joined:
    Jun 30, 2007
    Messages:
    613
    Er... Why?

    Danny
     
  8. JiminSA

    JiminSA Thread Starter

    Joined:
    Dec 15, 2011
    Messages:
    2,058
    That way I could have a variable number of occurrences of items. i.e. by putting arrays into cells, no?
     
  9. allnodcoms

    allnodcoms

    Joined:
    Jun 30, 2007
    Messages:
    613
    No mate, you can't put arrays into a table. Basically a table is an array. If you want to embed an array into a table you would do as you did with the edited entries: create another table an link each instance back to the parent table with an ID field.

    Danny
     
  10. JiminSA

    JiminSA Thread Starter

    Joined:
    Dec 15, 2011
    Messages:
    2,058
    Aha! On the premise that a serialised array is just a data string, I thought it would be possible to put it into a cell and guess what? You can! Check this
    Is this a case of the student teaching the mentor?:eek: No offense mate;)
     
  11. allnodcoms

    allnodcoms

    Joined:
    Jun 30, 2007
    Messages:
    613
    Er... No.

    Technically the contents of a field is just a string of 1s and 0s, so you can (I repeat for emphasis - technically) put what you like in it. But to go back to my previous reply - Why? You lose the ability to query the data, you'd have to read it in, unpack it, look through it, pack it back up and shoe horn it back in there...

    There are far more elegant ways of achieving the exact same thing without the use of power tools or large hammers :cool:

    Danny
     
  12. JiminSA

    JiminSA Thread Starter

    Joined:
    Dec 15, 2011
    Messages:
    2,058
    There is a valid reason why I would like this facility...

    The quick 'n dirty CMS I'm using for this vehicle database originally used this technique (Serialize/Unserialize) for the whole file. I decided that because this db will get very big (4-5 records added daily, ad infinitum) that it was time to go MySql...
    Now then, each vehicle entry can have any number of photographs uploaded and associated with it, id's of which are placed in an array within the serialised record.

    The CMS photo handling (add/delete/re-order etc.,) is all oriented to an array set up and is fairly complex - hence the desire to have an array within a MySql cell.

    Hope that clarifies it a bit, mate:) and I hope you don't think I was being arrogant in my last entry - I don't pretend that I could teach an old dog like you anything new!!!;)
     
  13. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1060783