Part of the EllisLab Network
   
 
Getting same info with diferent queries
Posted: 09 June 2008 12:21 PM   [ Ignore ]  
Summer Student
Avatar
Total Posts:  26
Joined  05-16-2008

Hi, I need some help, with a strange behaivour of CI or maybe im too novice.

//in a MODEL i have some funcions with queries 
function getUsers(){
 $qryUsrs 
$this->db>query('select * from users');
 return 
$qryUsrs->result_array();
}
function getDocs(){
 $qryDocs 
$this->db>query('select * from documents');
 return 
$qryDocs->result_array();
}
 
//in my CONTROLLER i call both 
$this->load->model('qry_model');
$data['users'$this->qry_model->getUsers();
$data['docs'$this->qry_model->getDocs();
$this->load->view('my_view',$data);

//in my VIEW I display both queries each in a table
echo $this->table->generate($users);
echo 
$this->table->generate($docs); 

The problem is that in both tables I see exactly the same data, i suppose i need to ‘clear’ the info in the array before getting another, someone knows how i must to proceed to get the correct data in each table?

Thanks in advance

 Signature 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Eros, cities builder.

Profile
 
 
Posted: 09 June 2008 01:45 PM   [ Ignore ]   [ # 1 ]  
Lab Assistant
RankRank
Total Posts:  262
Joined  10-02-2007

Try calling $this->table->clear() after generating the first table.

 Signature 

ウェブデザインイラストレーショングラフィックデザイン
“If I have to be smarter to use your technology, then your technology sucks.”

Profile
 
 
Posted: 09 June 2008 05:24 PM   [ Ignore ]   [ # 2 ]  
Summer Student
Avatar
Total Posts:  26
Joined  05-16-2008

thanks Samurai, I tried your advise, but I have seen that the problem is in the returned array
I placed a

if($users === $docs)
echo 
'ARE THE SAME....'

and efectively the string was printed out
im exploring the oci8_result.php to try to clean the array before populating.
BTW im using Oracle.
I see

function result_array() {
    
if (count($this->result_array) > 0)    // Is this necesary?, what if i clean it instead?
    
return $this->result_array;
    

Thanks

 Signature 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Eros, cities builder.

Profile
 
 
Posted: 09 June 2008 08:04 PM   [ Ignore ]   [ # 3 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  865
Joined  09-25-2007

I think you are right it looks like an oddity with oracle.

try

//result result array
  
$this->db->result_array = array(); 

between generating the first and last table, then you will know if this is a bug or not.

Profile
 
 
Posted: 10 June 2008 12:44 PM   [ Ignore ]   [ # 4 ]  
Summer Student
Avatar
Total Posts:  26
Joined  05-16-2008

Thanks gtech, I tried as you advised, im still getting same problem.

I’ve been playing around with oci8_result.php, trying to clear the array, the resource, some times im getting some errors, but always getting the same data in both arrays.

I think is time to post this problem in bugs area downer

 Signature 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Eros, cities builder.

Profile
 
 
Posted: 10 June 2008 02:48 PM   [ Ignore ]   [ # 5 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  865
Joined  09-25-2007

I also noticed that
your code:

$qryDocs $this->db>query('select * from documents'); 

should be

$qryDocs $this->db->query('select * from documents'); 

is this a typo in the forums? you have done the same in the users function as well


what do you get when you print_r after calling the model functions..

...
$this->load->model('qry_model');
$data['users'$this->qry_model->getUsers();
//clear result array You shouldn't have to do this!
// $this->db->result_array = array();
$data['docs'$this->qry_model->getDocs();
print_r($data);
... 
Profile
 
 
Posted: 11 June 2008 12:17 PM   [ Ignore ]   [ # 6 ]  
Summer Student
Avatar
Total Posts:  26
Joined  05-16-2008

Thanks for your observation gtech, effectively is an typo (just in the forum, not in the code).

When i print_r($data), yes, i can see that both arrays ($users and $docs)have the same information

further information will be appreciated

 Signature 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Eros, cities builder.

Profile
 
 
Posted: 11 June 2008 12:20 PM   [ Ignore ]   [ # 7 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  4777
Joined  03-23-2006

Can you take CodeIgniter out of the equation for a moment and just run those queries directly against the db?

Also, can you echo out $this->db->last_query() after each to see what CI is actually running?

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design

Profile
MSG
 
 
Posted: 11 June 2008 05:27 PM   [ Ignore ]   [ # 8 ]  
Lab Assistant
RankRank
Total Posts:  250
Joined  11-08-2006

Sounds like the same old oracle issue that keeps popping up, see my response here:

http://codeigniter.com/forums/viewthread/74105/#368167

You can also search the forums, I think this issue has come up in about 4 other posts.

- K

Profile
 
 
Posted: 11 June 2008 05:57 PM   [ Ignore ]   [ # 9 ]  
Summer Student
Avatar
Total Posts:  26
Joined  05-16-2008

To your 1st. observation Derek, when i print out $this->db->last_query() after each query, it displays correctly.

Also the file oci8_driver.php already has the change as noted kgill
here

I made queries by hand and there is no problem; the info displays correctly

<?php
    $qryUsrs 
='select * from users';
    
$qryDocs='select * from documents';
    
$cnx = @oci_connect('myusrname''mypass''//172.21.9.7:1525/admsfa');
    
$sent oci_parse($cnx$qryUsrs);
    
$sent2 oci_parse($cnx$qryDocs);
    
oci_execute($sent);
    
oci_execute($sent2);
    echo 
'<table>';
    while (
$row oci_fetch_array($sentOCI_RETURN_NULLS)){?>
        
<tr>
        <
td><?$row[0] ?></td>
        <
td><?$row[1] ?></td>
        <
td><?$row[2] ?></td>
        </
tr><?php
    }
    
echo '</table><br /><hr />';
    
// the 2dn qry
    
echo '<table><tr>';
    while (
$row oci_fetch_array($sent2OCI_RETURN_NULLS)){?>
        
<td><?$row[0] ?></td>
        <
td><?$row[1] ?></td>
        <
td><?$row[2] ?></td>
        </
tr><?php}
    
echo '</table>';
?> 

I want to point out that this is a existing application wich we’re migrating, to CI

thanks again for help supplied.

 Signature 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Eros, cities builder.

Profile
 
 
Posted: 12 June 2008 07:17 AM   [ Ignore ]   [ # 10 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  4777
Joined  03-23-2006

I’m sorry, I’m completely baffled.  Those are simple queries and you’ve done a good job of explaining and breaking down.  I just honestly have no explanation or further ideas.  Do you have another server/database you could test against?

 Signature 

DerekAllard.com - CodeIgniter, ExpressionEngine, and the World of Web Design

Profile
MSG
 
 
Posted: 12 June 2008 12:46 PM   [ Ignore ]   [ # 11 ]  
Summer Student
Avatar
Total Posts:  26
Joined  05-16-2008

Hi, dont worry i really apreciate your help, im gonna try to solve this mistery.

anyting i see, i will tell you.

thanks!

 Signature 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Eros, cities builder.

Profile
 
 
Posted: 13 June 2008 04:11 PM   [ Ignore ]   [ # 12 ]  
Summer Student
Avatar
Total Posts:  26
Joined  05-16-2008

Hi, im here again, just to point out some things i have noted.
About the trouble of getting the same data in two separate queries.

:: Follow the same pattern of my first post, if I compare the two arrays ($usrs === $docs) in my controller
  they are different. When I made the same evaluation in view they are the same! strange nop?. But still
  prints the same info in both tables, even if i print from the controller.
 
:: When I enable profiler, i can see 2 diferent queries with diff. execution times

no more ideas?

 Signature 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Eros, cities builder.

Profile
 
 
   
 
 
‹‹ helpe, uploading problem!      Error 1054 ››