0

I need to perform a database select functionality for each value in the array. Parameter theRequestApplicationName contains an array like

["fb","dropbox","twitter"]

i need select functionality, in the below mentioned query it should be like application.name = each value of array. Please help me to solve this

ApplicationLogoutUrl = function (theRequestId, theRequestApplicationName, theRequestOrg, connection, res)
{
   theQuery = "select org_uses_app.app_logout_url 
                from  application, org_uses_app 
                where application.id=org_uses_app.application 
                and application.name = --";
}
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • try this https://stackoverflow.com/questions/16240041/sql-search-multiple-values-in-same-field – zimorok Feb 26 '20 at 04:28
  • First of all you should use a framework with ORM. Secondly, if you are not using ORM at least don't use the input directly in SQL and use place holders with prepared statements. Your life will be a lot easier! – Navid Feb 26 '20 at 05:02

3 Answers3

0

for multiple search value, you can use the sql query IN as in the answer here SQL search multiple values in same field

zimorok
  • 326
  • 1
  • 11
0

Your sql query should be like this -

//$array variable is your array name like below
// $array = ["fb","dropbox","twitter"];

 theQuery = "select org_uses_app.app_logout_url from  application, org_uses_app 
             where application.id=org_uses_app.application and application.name IN 
             ('$array[0]','$array[1]','$array[2]')";
Hitesh Kumar
  • 383
  • 2
  • 6
  • sorry i want to select app_logout_url for each value (). ie "select org_uses_app.app_logout_url from application where application.name $array[0] next "select org_uses_app.app_logout_url from application where application.name $array[1] like this dynamically – user2830078 Feb 26 '20 at 07:27
  • Is you want to make 3 different queries with where condition ? – Hitesh Kumar Feb 26 '20 at 07:43
  • no i want each array element in where clause. need to get the logout url of $array[0] next logout url of $array[1] for each array index i – user2830078 Feb 26 '20 at 08:12
0

Basic structure of the query can be

    SELECT item FROM database.table WHERE firstCondition OR secondCondition

Assuming the database is named applications, has apps table with following attributes id and name with one record {id: 'fb', name: 'facebook'} the query in php will be

    SELECT app_logout_url 
    FROM applications.apps 
    WHERE id = fb  OR name = facebook;
Patrick N.
  • 53
  • 3
  • 6
  • i need to make it dynamic. ie for each value of array element. i want to each value of array element in the where clause dynamically – user2830078 Feb 26 '20 at 07:26