ItsPronounced
ItsPronounced

Reputation: 5463

two query results in 1 $variable

I'm trying to use codeigniter activerecords to pull some records from two tables that have the same structure. For example I have a MARKET table with two fields (name, name_spanish) and I have an APPLICATION table with the same two fields (name, name_spanish).

Can I create a $data variable and put the results of each query into it? Then I'd want to check the results like this psuedocode $spanish = $data['name_spanish'] where $data['name'] = "Hello"

Can this be accomplished?

Upvotes: 0

Views: 217

Answers (3)

horatio
horatio

Reputation: 1436

This sounds like a UNION query.

SELECT * FROM table1 WHERE foo = 1 
  UNION SELECT * FROM table2 WHERE bar = 3 AND baz = 3

I don't think CodeIgniter's ActiveRecord supports union queries, so use the query method.

Upvotes: 4

Dutchie432
Dutchie432

Reputation: 29160

$spanish = array(
    "hello" => "hola",
    "dog" => "perro",
    "car" => "carro"
)

$english = array(
    "hello" => "hello",
    "dog" => "dog",
    "car" => "car"
)

$data = array(
    "sp" => $spanish,
    "en" => $english
)

echo $data['sp']['hello']; //yields 'hola'
echo $data['en']['hello']; //yields 'hello'

$lang = "sp"
$word = "dog";
echo $data[$lang][$word]; //yields 'perro'

Upvotes: 2

Ilya Saunkin
Ilya Saunkin

Reputation: 19820

Generally speaking, yes you can. Also you can use UNION to get both result sets in the same iterator.

Upvotes: 1

Related Questions