5

I am creating an inventory system for myself that contains a list of items (with description, count, last date used, etc.) that also contains a status for the item. At the most basic level, I am listing all items from a MySQL query (SELECT * FROM Items), along with their status in a SELECT HTML FORM element (int datatype, 0/1/2 status indicator).

I want to be able to update any item in this list without having to parse through every item that was listed and do a comparison against the SQL server's contents. I would imagine this is not the best practice and the better way to accomplish this would be to compile a list of items that are changing and submit them via HTTP POST. Is this correct? What would be the best way to accomplish this?

Frank
  • 71
  • 4
  • 3
    This is a good question, but I'm too busy (lazy) to write the sort of answer it deserves - but you might want to take a look at ORM solutions, which take a lot of the pain out of building this sort of thing. Questions like this are a good place to start: http://stackoverflow.com/questions/108699/good-php-orm-library – Iain Collins May 06 '12 at 16:31
  • Thank you -- I have not coded in a while and I am definitely out of touch with common practices. Took C++ in high school/college just before everything shifted towards OOP Java, so even PHP5 is new to me. I'll read up on ORM, especially Doctrine and RedBean.. they seem the best. – Frank May 06 '12 at 16:38
  • Good luck! Would say that see if you can find one you like that does parameterization (i.e. auto escaping of values) too (confusingly some do parameterization, but not actual escaping in all instances so worth checking the manual). Doctrine's ORM is probably a good fit, but there are so many I'm hesitant to recommend a specific one :) – Iain Collins May 06 '12 at 16:45
  • So would you want to update just one row? or perhaps any rows that have been modified? If so something like a ExtJS grid editor might be a good fit, its store can let you find out the modified records. – gunnx May 10 '12 at 12:46

1 Answers1

1

Use Ajax. Clean and simple. Fast way to implement is using JQuery.

<select id="target">
    <option value="option1" selected="selected">Option 1</option>
    <option value="option2">Option 2</option>
  </select>

javascript

$('#target').change(function () {
$.ajax({

    type: "POST",
    url: "page.php",
    data: 'id=something' ,
    success: function (msg) {
        //after php response
    }
});

});

See change and ajax

Ciro
  • 662
  • 7
  • 19