I am working on an HTML/JavaScript project where I want to query a mySQL database and hand the query results back to my code for parsing. Normally I would use arrays and such (cause that's really what I know how to do), but I think that using objects would be so much cleaner in JavaScript. Here is what it will basically do:
* JavaScript will call a PHP form to query the DB (asynchronously)
* PHP will return the results, maybe as many as 5000 results with 10-20 fields each.
* JavaScript will store the result in an (object? / array?) and use it to build a list. It will also be used for sorting, filtering and randomly accessing data from the list.
I know how to do the first two steps, but then what? I have read about JSON, and believe this is how it should be done. And I am using PHP5, so I can hand a JSON formatted string back to the JS. But what does the object look like?
Let me use a music analogy as an example. Suppose I have the following fields in my database: title, album, year, artist and genre. Would my object be a "song" with each field being an attribute? Then how do I build a playlist - is this an array of objects? Or would my object be a playlist, with each song being another object? Is this possible?
I am new to OOP, so any help is, well, helpful.
* JavaScript will call a PHP form to query the DB (asynchronously)
* PHP will return the results, maybe as many as 5000 results with 10-20 fields each.
* JavaScript will store the result in an (object? / array?) and use it to build a list. It will also be used for sorting, filtering and randomly accessing data from the list.
I know how to do the first two steps, but then what? I have read about JSON, and believe this is how it should be done. And I am using PHP5, so I can hand a JSON formatted string back to the JS. But what does the object look like?
Let me use a music analogy as an example. Suppose I have the following fields in my database: title, album, year, artist and genre. Would my object be a "song" with each field being an attribute? Then how do I build a playlist - is this an array of objects? Or would my object be a playlist, with each song being another object? Is this possible?
I am new to OOP, so any help is, well, helpful.