CodeIgniter Forums
problem in finding second maximum value - 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: problem in finding second maximum value (/showthread.php?tid=40832)

Pages: 1 2


problem in finding second maximum value - El Forum - 04-20-2011

[eluser]Bigil Michael[/eluser]
but it shows error
Quote:A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: controllers/election_result.php

Line Number: 42

A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: controllers/election_result.php

Line Number: 43

in the model we use
Quote:if($query->num_rows() > 0)
{
$row = $query->row();

// display results
echo '<pre>';
print_r($query->row());
echo '</pre>';
}

but it willnot print anything


problem in finding second maximum value - El Forum - 04-20-2011

[eluser]Bigil Michael[/eluser]
ok ok
now it prints result of the person who has maximum votes

i want 2nd maximum


problem in finding second maximum value - El Forum - 04-20-2011

[eluser]John_Betong_002[/eluser]
Modify your SQL so that it returns the top maybe 5 rows (using LIMIT 0,5).

Display all the $query-result(). Ensure the data is what you want. It should be the second row-&gt;canditate_ votes.

Display your results.

&nbsp;
&nbsp;
&nbsp;


problem in finding second maximum value - El Forum - 04-20-2011

[eluser]Bigil Michael[/eluser]
when the result become 0
ie if the year and constituency_id didnot matches

at that time it shows error on controller as undefined property

how will i avoid that error?????


problem in finding second maximum value - El Forum - 04-20-2011

[eluser]John_Betong_002[/eluser]
[quote author="Bigil MM" date="1303310808"]
when the result become 0
ie if the year and constituency_id didnot matches

at that time it shows error on controller as undefined property

how will i avoid that error?????
[/quote]
The code I supplied had a check to prevent the undefined property error.

If you chose to remove the check then the error will always appear.
Code:
#query = $this->db->query($sql);
  if($query->num_rows() > 0)
  {
    // IT IS OK TO DO SOMETHING BECAUSE THERE IS VALID DATA
  }

&nbsp;
&nbsp;
&nbsp;


problem in finding second maximum value - El Forum - 04-20-2011

[eluser]Bigil Michael[/eluser]
thank you so much
i have solved my problem


problem in finding second maximum value - El Forum - 04-20-2011

[eluser]John_Betong_002[/eluser]
I am glad I was able to help.

Can you mark this post as SOLVED and supply your solution so that others may gain from your knowledge.
&nbsp;


problem in finding second maximum value - El Forum - 04-20-2011

[eluser]Bigil Michael[/eluser]
how to mark it as solved