Welcome Guest, Not a member yet? Register   Sign In
db results are not right
#1

[eluser]samseko[/eluser]
Following appears to work, except it isn't displaying the db results in ascending order by RealPrice. What's wrong with the code?!

$where = "`Category` = '$cat'";
$order = "`RealPrice` ASC";
$data['query'] = $this->db->where($where)->order_by($order)->get('products');
#2

[eluser]Stelian Mocanita[/eluser]
What type is your RealPrice field? A common miss-behavior is you having your RealPrice as a char type(varchar, text, longtext, etc) and not INT and thus resulting a different result set than expected.

As a workaround you might try:

Code:
$clean['Category'] = $cat;
$this->db->order_by('RealPrice', 'ASC');
$data['query']  = $this->db->get_where('products', $clean)

You could try this cleaner snippet as I had some issues with methods chaining so this way you might know for sure what happens and where.
#3

[eluser]Mark Skilbeck[/eluser]
After your get() call. Do a
Code:
die ( $this->db->last_query() );
And see if the output is what you expect.

I would do as mentioned above: let the db methods do the work (just pass it arguments).
#4

[eluser]TheFuzzy0ne[/eluser]
You're escaping values that are escaped for you already.

Try this:
Code:
$this->db->order_by('RealPrice', 'asc');
$query = $this->db->get_where('products', array('Category' => $cat))
#5

[eluser]samseko[/eluser]
Thanks for the input guys.. the issue was with the field type.. they were are all text, this one is an INT now, and problem resolved. Smile




Theme © iAndrew 2016 - Forum software by © MyBB