CodeIgniter Forums

Full Version: Getting same info with diferent queries
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2

El Forum

[eluser]tjmthome[/eluser]
Hi, I need some help, with a strange behaivour of CI or maybe im too novice.

Code:
//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

El Forum

[eluser]Armchair Samurai[/eluser]
Try calling $this->table->clear() after generating the first table.

El Forum

[eluser]tjmthome[/eluser]
thanks Samurai, I tried your advise, but I have seen that the problem is in the returned array
I placed a
Code:
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
Code:
function result_array() {
    if (count($this->result_array) > 0)    { // Is this necesary?, what if i clean it instead?
    return $this->result_array;
    }

Thanks

El Forum

[eluser]gtech[/eluser]
I think you are right it looks like an oddity with oracle.

try
Code:
//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.

El Forum

[eluser]tjmthome[/eluser]
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 :down:

El Forum

[eluser]gtech[/eluser]
I also noticed that
your code:
Code:
$qryDocs = $this->db>query('select * from documents');

should be
Code:
$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..
Code:
...
$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);
...

El Forum

[eluser]tjmthome[/eluser]
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

El Forum

[eluser]Derek Allard[/eluser]
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?

El Forum

[eluser]kgill[/eluser]
Sounds like the same old oracle issue that keeps popping up, see my response here:

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

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

- K

El Forum

[eluser]tjmthome[/eluser]
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
Code:
<?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($sent, OCI_RETURN_NULLS)){?&gt;
        <tr>
        <td>&lt;?= $row[0] ?&gt;</td>
        <td>&lt;?= $row[1] ?&gt;</td>
        <td>&lt;?= $row[2] ?&gt;</td>
        </tr>&lt;?php
    }
    echo '</table><br /><hr />';
    // the 2dn qry
    echo '<table><tr>';
    while ($row = oci_fetch_array($sent2, OCI_RETURN_NULLS)){?&gt;
        <td>&lt;?= $row[0] ?&gt;</td>
        <td>&lt;?= $row[1] ?&gt;</td>
        <td>&lt;?= $row[2] ?&gt;</td>
        </tr>&lt;?php}
    echo '</table>';
?&gt;

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

thanks again for help supplied.
Pages: 1 2