CodeIgniter Forums
Database getting Error - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Database getting Error (/showthread.php?tid=17702)



Database getting Error - El Forum - 04-13-2009

[eluser]Shahgeb[/eluser]
I am using query below

$this->db->distinct()->select("jobtitle")->from('users')->where('status', 'Acive');
$rs = $this->db->get();
echo $rs->num_rows();

It return 2 record from database

but above query generate below mentioned query using _select_compile()
echo $this->db->_select_compile();
$rs = $this->db->query("SELECT DISTINCT `jobtitle` FROM (`users`) WHERE `status`
= 'Active'");
echo $rs->num_rows();

It return 3 record

BUT in database there is 3 record

Quote:where i am wrong ????
Smile


Database getting Error - El Forum - 04-13-2009

[eluser]jedd[/eluser]
Hehe .. maybe it thinks its FORTRAN. Hmm .. okay, a bit too nerdy.

I'd suggest you enable the profiler - it'll show you, at the bottom of your view, the two actual SQL commands being run - so you'll be able to spot immediately what the AR command is actually being translated into.


Database getting Error - El Forum - 04-13-2009

[eluser]TheFuzzy0ne[/eluser]
What are the three rows you're expecting to be selected?


Database getting Error - El Forum - 04-13-2009

[eluser]Shahgeb[/eluser]
I am getting your point but my point is why there is difference in their result having the same query
?????


Database getting Error - El Forum - 04-13-2009

[eluser]jedd[/eluser]
I'm unconvinced that you are getting my point.

My point is that your two queries are not identical. This is evinced by the fact that they return non-identical results.

So, as a way of answering your question, you will first need to establish what is different between the two queries when they hit the database.

The most obvious, and easiest, way of doing this is to insert one line into your controller's constructor, as I suggested, to take advantage of the [url="http://ellislab.com/codeigniter/user-guide/general/profiling.html"]CI Profiler[/url]:

Code:
$this->output->enable_profiler(TRUE);



Database getting Error - El Forum - 04-13-2009

[eluser]Shahgeb[/eluser]
hmm ok thanks for the corporation


Database getting Error - El Forum - 04-14-2009

[eluser]mikeyhell[/eluser]
I never really liked chaining together like that, I did it for a while and realized it was more difficult to read the code, hence, errors were more difficult to spot.