• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting same info with diferent queries

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
$data['users'] = $this->qry_model->getUsers();
$data['docs'] = $this->qry_model->getDocs();

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

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

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;


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

//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.

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:

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..
$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();

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

[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?

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


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

- K

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

I made queries by hand and there is no problem; the info displays correctly
    $qryUsrs ='select * from users';
    $qryDocs='select * from documents';
    $cnx = @oci_connect('myusrname', 'mypass', '//');
    $sent = oci_parse($cnx, $qryUsrs);
    $sent2 = oci_parse($cnx, $qryDocs);
    echo '<table>';
    while ($row = oci_fetch_array($sent, OCI_RETURN_NULLS)){?&gt;
        <td>&lt;?= $row[0] ?&gt;</td>
        <td>&lt;?= $row[1] ?&gt;</td>
        <td>&lt;?= $row[2] ?&gt;</td>
    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>
    echo '</table>';

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

thanks again for help supplied.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.