Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best practice to display a list of items that may change via HTTP POST (PHP + MySQL)

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?

like image 772
Frank Avatar asked Nov 14 '22 05:11

Frank


1 Answers

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

like image 165
Ciro Avatar answered Nov 16 '22 04:11

Ciro