Welcome Guest, Not a member yet? Register   Sign In
can I return 2 sets of results from 2 different talbes from one function? if yes- how to?
#8

[eluser]boltsabre[/eluser]
Sorry, been offline the last 12 or so hours.

Right, so it looks like we're getting the result from your model (as an array, contain 4 values), and it's being passed to your view from your controller yes?

Okay, it should be pretty simple...you have an array in your view that you want to access, looking like this:
Code:
$search_results_returned; //it's an array, containing:
$search_results_returned['post_q_1_empty'] //value = bool(true)
$search_results_returned['post_q_1_full'] //value = bool(false)
$search_results_returned['post_q_2_empty'] //value = bool(false)
$search_results_returned['post_q_2_full'] //value = array (of your search result data.

To do anything, you have to access the key of $search_results_returned that you want to check.

For example, if you wanted to check if 'post_q_1_empty' was true or false in your view you'd do it like this:
Code:
if($search_results_returned['post_q_1_empty'] == false){
   //do something
}else{
   //do something else
}

To check if you have a search result, you need to check if either both 'post_q_1_empty' and 'post_q_2_empty' == true, or if either post_'q_1_full' and 'post_q_2_full'!= false, like this:
Code:
if($search_results_returned['post_q_1_empty'] == true && $search_results_returned['post_q_2_empty'] == true){
   //no search results were returned
}

...or...
if($search_results_returned['q_1_full'] != false || $search_results_returned['q_2_full'] != false){
   //we have a search result in one of them...
}

To access your search result 'post_q_2_full', I'm pretty sure this will work:
Code:
if($search_results_returned['post_q_1_empty'] != false){
   foreach ($search_results_returned['post_q_1_empty'] as $row){
      echo $row->user_image_filename;
   }
}
[/code]


Messages In This Thread
can I return 2 sets of results from 2 different talbes from one function? if yes- how to? - by El Forum - 06-20-2012, 04:26 AM



Theme © iAndrew 2016 - Forum software by © MyBB