Try to search your question here, if you can't find : Ask Any Question Now ?

Dynamic query with an array

HomeCategory: stackoverflowDynamic query with an array
Avatarpushpa asked 1 week ago

In my Repository I have the following method that gets me the data that I need:

public function data($select, $where, $value) {
    return $this->createQueryBuilder('t')
        ->select($select)
        ->where('t.' . $where  . ' = :where')
        ->setParameter('where', $value)
        ->getQuery()
        ->getResult()
        ;
}

That works great but I need to specify the query a little bit more. So I have an array that looks like this:

array('country' => 'USA', "city" => 'Chicago', 'age' => 24);

Key of the array = the column name

Value of the array = value in the database

Note that each column could be from another table. The best way would be to get the table name by the column name (since each table has individual columns) or there could be just another array with all table names.

The goal

If I call the function data('id', 'car', 'bmw'), then I should get a result, IF car = ‘bmw’ AND country = ‘USA’ AND city = ‘Chicago’ AND age = 24.

How can I do this?

1 Answers
Best Answer
AvatarFernando answered 1 week ago
Your Answer

7 + 18 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com