Welcome Guest, Not a member yet? Register   Sign In
Database getting Error
#1

[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
#2

[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.
#3

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

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

[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);
#6

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

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




Theme © iAndrew 2016 - Forum software by © MyBB