Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Associating multiple MySQL queries w/ PHP?

Tags:

php

mysql

I am trying to create a simple inventory request system. A user can enter multiple SKU's that will query the inventory database.

My problem is I am trying to do is associate these multiple queries into a type of list. This list can later be retrieved and contains all queries that were submitted simultaneously. When the list is filled it can then be deleted.

Is this possible? I am just looking to be pointed in the right direction.

Thanks

like image 202
cds5059 Avatar asked Nov 06 '22 12:11

cds5059


2 Answers

If I understand the problem correctly, you are looking for a query to retrieve data when someone searches for multiple SKUs in a table. Is that correct? See query below if it is.

SELECT some_data FROM some_table WHERE sku IN ('SSDF3','GHG56',...'HG09');
like image 66
gsharma Avatar answered Nov 11 '22 04:11

gsharma


You will need to associate the table with another table in the database, where it will be a Many to Many Table joining both the Inventory Table and the Type List based on Foreign Key matched to SKU.

YOU CAN QUERY THE FOLLOWING
SELECT inventory.* FROM inventory LEFT JOIN InvLinkedList ON InvLinkedList.SKU = Inventory.SKU WHERE InvLinkedList.typeID = 2

You will need to have Inventory Table with all the items, a InventoryType table with ID and Type as column and a MANY TO MANY connecting TABLE InvLinkedList with two indexed columns (SKU and TYPE ID). You will need to define relationship of these tables, where ON DELETE, it will CASCADE on type list. So that when ever you delete a type it will remove the rows with typeID in the InvLinkedList but will not remove the item in Inventory. The opposite will happen when you remove an item with SKU.

I hope this will be the solution. As for multiple type, you can create a PHP function to return the above mentioned query with a defined type.

like image 27
Raftalks Avatar answered Nov 11 '22 03:11

Raftalks