I have a system that controls phones. As we all know, phones can have one sim or two. It is known that there are different operators. Therefore, I want to show a filter with all possible combinations of telephones and operators. Today I have a universe of 10 thousand devices. At the end, the system shows device measurements, but the user can filter statistics by phone ( apple , samsung , nokia , etc.), Model and .
So, I have this form that will display all combinations currently using the device’s universe.
At the end, I have a filter as follows:
<select id="filter" multiple="multiple"> <optgroup label="Model"> <option value="1">iPhone</otion> <option value="2">Samsung</otion> <option value="3">Asus</otion> </optgroup> <optgroup label="Operator"> <option value="1">Digicel</otion> <option value="2">FLOW</otion> <option value="3">Rogers</otion> <option value="4">Telus</otion> <option value="5">Bell</otion> ... ... <option value="2,3">FLOW,Rogers</otion> <option value="2,5">FLOW,Bell</otion> <option value="3,1">Rogers,Digicel</otion> ...[I don't know all current combinations..this is a dynamic filter] </optgroup> </select>
Database model
So, I have a basic device table (I am going to put only columns that are “important”):
devices ------------ id_device (pk) | id_manufacter (fk) | id_model (fk) ------------ 1 | 1 | 10 2 | 1 | 13 3 | 1 | 14 4 | 2 | 5 4 | 2 | 6 .......... 99| 60 | 811 .......... operators ------------ id_operator (pk) | operator_name | operator_ip ------------ 1 | "Digicel" | 10.192.112.29 2 | "FLOW" | 10.192.112.33 3 | "Rogers" | 10.192.112.54 4 | "Telus" | 10.192.112.111 5 | "Bell" | 10.192.112.233 .......... 4654 | "Vivo" | 10.192.112.44 ..........
The IP address I use to perform some measurements - it doesn’t matter now - and, of course, these are fake ips.
And I have this staging table:
------------ id_device | id_operator ------------ 1 | 1 1 | 2 2 | 1 3 | 3 4 | 2 4 | 3 5 | 2 5 | 5 6 | 2 6 | 5 ......... 129129 | 3 129129 | 1
What I want:
A method or idea - as you prefer - is filtered by the "exclusive" options. If I select the <option value="2,5">FLOW,Bell</otion> , it will return all devices that have this SIM combination: 2,5 . In this case - with multiple entries - device identifier 5 and 6 .
Users can choose
<option value="1">Digicel</otion> <option value="3">Rogers</otion> <option value="2,3">FLOW,Rogers</otion> <option value="2,5">FLOW,Bell</otion>
In this case, he must return all devices that have only a SIM card with operator No. 1 or SIM with operator No. 3 or SIM cards with operator No. 2 And operator No. 3 or SIM cards with operator No. 2 And operator No. 5 :
devices # 2, # 3, # 4, # 5, # 6.
In the database, I created a package using function :
FUNCTION generalMeasurements ( models IN VARCHAR2, manufacturers IN VARCHAR2, idsoperators IN VARCHAR2 ) RETURN sys_refcursor IS vmanufacturers table_string := str2table(manufacturers); vidmodels table_string := str2table(models); cout sys_refcursor; BEGIN open cout for select count(*), bla bla bla from devices inner join operators_device on id = id_device inner join operator on id_operator = operator_id WHERE ( (models IS NULL) OR id_model IN ( SELECT COLUMN_VALUE FROM TABLE (vidmodels)) ) AND ( (manufacturers IS NULL) OR id_manufacturer IN ( SELECT COLUMN_VALUE FROM TABLE (vmanufacturers)) ); END; CREATE OR REPLACE TYPE table_string IS TABLE OF VARCHAR2(30); CREATE OR REPLACE FUNCTION str2table (p_str IN VARCHAR2) RETURN table_string IS l_str LONG DEFAULT p_str || ','; l_n NUMBER; l_data table_string := table_string (); BEGIN LOOP l_n := INSTR (l_str, ','); EXIT WHEN (NVL (l_n, 0) = 0); l_data.EXTEND; l_data (l_data.COUNT) := LTRIM (RTRIM (SUBSTR (l_str, 1, l_n - 1))); l_str := SUBSTR (l_str, l_n + 1); END LOOP; return l_data; END;
So ... any ideas for this?