有效地保存动态列表项

时间:2015-06-29 10:02:15

标签: php mysql

我的超级市场存储在我的数据库中。对于每个超市,在管理区域中,用户可以创建带有产品的购物清单,并通过检查(=用户已经购买产品)或取消选中它们来跟踪产品(=用户仍然需要购买产品)。我的问题是如何在MySQL中有效地存储购物清单项目?

我的示例数据标记:

<form>

   <h1>Supermarket: "City Store"</h1>

   <p>Create/edit your shopping list:</p>

   <ul id="shopping-list">
     <li><input type="text">Tomatoes</input> <input type="checkbox"></li> 
     <li><input type="text">Apples</input> <input type="checkbox" checked="checked"></li> 
     <li><input type="text"></input> <input type="checkbox"></li> 
   </ul>

   <button id="add-list-item">Add list item</button>

   <button id="save-list-items">Save</button>

</form>

$('#add-list-item').on('click', function() { 
 $('#shopping-list').append('<li> <input type="text"></input><input type="checkbox"></li>');
});

在这种情况下,当用户登录时,他发现他过去已经在列表中添加了两个产品,即西红柿和苹果。因为他已经买了苹果,他已经检查过了。如果他想添加产品,他可以按下按钮。

在我的MySQL环境中,我已经有了一张桌子&#34;超市&#34;。为了存储购物清单项目,我想创建一个额外的表格&#34; shopping-list-items&#34;包含以下字段:

 - id
 - id_supermarket
 - content
 - status (1 = 'checked', 0 = 'still unchecked')
 - date_created
 - date_updated
 - date_checked

如您所见,我希望保存每个列表项的日期,以及创建,更新和检查时的日期。

如何通过POST将购物清单的数据发送到我的数据库,并区分已检查和未检查的项目?我基本上知道如何通过name属性将数据发送到数据库并保存它们,但在这种情况下,我想单独保存每个条目,同时考虑复选框状态,我不知道如何处理它。 / p>

0 个答案:

没有答案
相关问题