Welcome Guest, Not a member yet? Register   Sign In
Why isn't this database query returning correctly?
#1

[eluser]A_funs[/eluser]
$this->db->where('email', $email);
$this->db->from('people');
$this->db->limit(1);
$line = $this->db->get();
$line = $line->result();

The result does not get where $email is equal to 'email'

it is returning the first row of the database table. it seems I am following the documentation correctly...

Thanks
#2

[eluser]Aken[/eluser]
Use $this->db->last_query() to see what's wrong with the query being produced.
#3

[eluser]rip_pit[/eluser]
Sorry but your code is working fine here as is.


Enable debugger in your controller and see what's shown in the sql panel
Code:
$this->output->enable_profiler(TRUE);

or simply or use the last_query method to output the generated query.
put this code after you last line :
Code:
die( $this->db->last_query() );

Try the short hand code :
Code:
$query = $this->db->select(*)
->where('email',$email)
->limit(1)
->get('people');

$line = $query->row();

Note that you can replace ->result() with ->row() when using limit(1).
see http://ellislab.com/codeigniter/user-gui...sults.html for more details
#4

[eluser]timmahoney[/eluser]
Theoretically, if you didn't have the where conditional set, it would return the first row of the table, so my guess is that $email is not being passed correctly.
#5

[eluser]A_funs[/eluser]
haha yea that was it.... the name attribute wasn't set on my input field, should have caught that.

Thanks to the other posts as well, learned some good techniques




Theme © iAndrew 2016 - Forum software by © MyBB