Welcome Guest, Not a member yet? Register   Sign In
Active Records Query Results Not What I Expected
#1

[eluser]Lane[/eluser]
Thanks in advance for reading my post.

First of all, I am new to CodeIgniter and this forum and so far, I am liking the framework very much.

I am using the Active Records' method get_where to query a table. When the object returns, it has 3 rows. First row has no data, second row is the row I need, and third row also has no data.

I have a table with 3 rows of data in it, which I assume accounts for the 3 rows returned in the object. What is puzzling is that there's only one row that meets the where clause criteria. So my question is, why are 2 null rows returned and how to I limit this to the actual row of valid data?

Below are the code frags:

Query:

Code:
$result = $this->db->get_where('my_table', array('email_address' => $email_address));

I interpret this to be: "SELECT * FROM my_table WHERE email_address = the valued contained in the variable $email_address"

I know for a fact that the variable email address contains a single email address as it should.

To process the results, I use the following code:

Code:
if ($result->num_rows() > 0)
        {
            
            foreach ($result->result() as $row)
            {
                echo 'Column 1: '.$row->column1.'<br />';
                echo 'Column 2: '.$row->column2.'<br /><br />';
            }
        }

Where column1 and 2 are valid column names in my_table.

The output is as follows:

Column 1:
Column 2:

Column 1: columnvalue1
Column 2: columnvalue2

Column 1:
Column 2:


Any thoughts, comments, tips, advice, etc. is appreciated.


Lane
#2

[eluser]Lane[/eluser]
UPDATE:

I am not sure how or why, but when I echo the query results in the controller, rather than the view, I get back 1 row, which is what I expect.

The only other problem I'm having now is getting one value from the row to be displayed in the view.

Any thoughts on that would be appreciated.
#3

[eluser]plain jane[/eluser]
Can you tell what you get when you execute the following query:

Code:
$result = $this->db->get('my_table');

Thanks,
ci user
#4

[eluser]danmontgomery[/eluser]
To see queries being run:
Code:
$this->output->enable_profiler();

Quote:The only other problem I’m having now is getting one value from the row to be displayed in the view.
Not sure I understand this. http://ellislab.com/codeigniter/user-gui...sults.html?




Theme © iAndrew 2016 - Forum software by © MyBB