mo Posted June 30, 2007 Share Posted June 30, 2007 I have one more piece of logic to add to my cart. My online store has many menus from various stores that a customer can order from. My cart should only allow items from one menu to be added to the cart. I need a query to check and make sure only items from 1 menu/store has been added to the cart. Cart Table ---------------------------------------------------------------------------------------------- Cart ID | smid | store_name | cart_session_id | cart_qty | price | etc....... ---------------------------------------------------------------------------------------------- (auto increment)| 1001 | McDOnalds | 2131feffde434c | 2 | 2.00 | ....... (auto increment)| 0890 | McDOnalds | 2131feffde434c | 1 | 1.00 | ....... (auto increment)| 0234 | McDOnalds | 2131feffde434c | 5 | 3.25 | ....... (auto increment)| 0100 | Burger King | 2131feffde434c | 1 | 6.00 | ....... //Bad Row The Burger King row should never be allowed to post to the table. Before writing to the table, I need to check if the item being added belongs to the store that the current cart items are from. Any thoughs on how to do this check cleanly? Link to comment https://forums.phpfreaks.com/topic/57818-mysql-query-help-check-table-contents-for-unique-key/ Share on other sites More sharing options...
mmarif4u Posted June 30, 2007 Share Posted June 30, 2007 My idea is : Make a new field in that table as active. When the menu1/ cart script runs put X or something in the active field from that cart script. And when in ur query selecting it Add where clause and check that active='X' if X than show the row, If not then escape it. Like: Cart ID | smid | store_name | cart_session_id | cart_qty | price | active ---------------------------------------------------------------------------------------------- (auto increment)| 1001 | McDOnalds | 2131feffde434c | 2 | 2.00 | X (auto increment)| 0890 | McDOnalds | 2131feffde434c | 1 | 1.00 | X (auto increment)| 0234 | McDOnalds | 2131feffde434c | 5 | 3.25 | X (auto increment)| 0100 | Burger King | 2131feffde434c | 1 | 6.00 | (Empty) Hope this will give an idea. Link to comment https://forums.phpfreaks.com/topic/57818-mysql-query-help-check-table-contents-for-unique-key/#findComment-286470 Share on other sites More sharing options...
JP128 Posted June 30, 2007 Share Posted June 30, 2007 you could make it to where before you insert anything add this <?php $sql_check = mysql_query("SELECT * FROM tbl_name limit 1"); while($check = mysql_fetch_assoc($sql_check)){ $storename = $check['store_name']; } if(mysql_num_rows(mysql_query("SELECT * FROM tbl_name WHERE store_name='$storename'")) < 1){ mysql_query("INSERT THE STORE NAME HERE"); } ?> Link to comment https://forums.phpfreaks.com/topic/57818-mysql-query-help-check-table-contents-for-unique-key/#findComment-286481 Share on other sites More sharing options...
mo Posted June 30, 2007 Author Share Posted June 30, 2007 Thanks JP128, I altered a bit but your logic did the trick. Link to comment https://forums.phpfreaks.com/topic/57818-mysql-query-help-check-table-contents-for-unique-key/#findComment-286810 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.