开发者

two query results in 1 $variable

开发者 https://www.devze.com 2023-02-05 15:18 出处:网络
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 APPL

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 开发者_Go百科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?


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.


$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'


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

0

精彩评论

暂无评论...
验证码 换一张
取 消