Welcome Guest, Not a member yet? Register   Sign In
selecting data from 2 tables
#21

[eluser]Bigil Michael[/eluser]
i used code like this
Quote:function select_winner($cid,$elect_year)
{
$query = $this->db->where('constituency_id', $cid)
->where('elect_year', $elect_year)
->where('candidate_votes','(SELECT MAX(candidate_votes)FROM candidate_details)')
->get('candidate_details');
return $query->result_array();
}

but it willnot print the result;
#22

[eluser]toopay[/eluser]
debug it..., what that query looks like, paste it here..
Code:
function select_winner($cid,$elect_year)
      {
      $query = $this->db->where('constituency_id', $cid)
            ->where('elect_year', $elect_year)
            ->where('candidate_votes','(SELECT MAX(candidate_votes)FROM candidate_details)')
            ->get('candidate_details');
      var_dump($this->db->last_query());
      exit;
      return $query->result_array();  
      }
#23

[eluser]Bigil Michael[/eluser]
print error like this
Quote:string(169) "SELECT * FROM (`candidate_details`) WHERE `constituency_id` = '2' AND `elect_year` = '2011' AND `candidate_votes` = '(SELECT MAX(candidate_votes)FROM candidate_details)'"
#24

[eluser]toopay[/eluser]
Code:
function select_winner($cid,$elect_year)
      {
      $query = $this->db->where('constituency_id', $cid)
            ->where('elect_year', $elect_year)
            ->where('candidate_votes = (SELECT MAX(candidate_votes)FROM candidate_details)')
            ->get('candidate_details');
      return $query->result_array();  
      }
#25

[eluser]Bigil Michael[/eluser]
but it willnot print the correct result
#26

[eluser]toopay[/eluser]
run this and paste it's result here..
Code:
function select_winner($cid,$elect_year)
      {
      $query = $this->db->where('constituency_id', $cid)
            ->where('elect_year', $elect_year)
            ->where('candidate_votes = (SELECT MAX(candidate_votes)FROM candidate_details)')
            ->get('candidate_details');
      var_dump($this->db->last_query());
      var_dump($query->result_array());
      exit;
      return $query->result_array();  
      }
#27

[eluser]Bigil Michael[/eluser]
print like this

string(167) "SELECT * FROM (`candidate_details`) WHERE `constituency_id` = '2' AND `elect_year` = '2011' AND `candidate_votes` = (SELECT MAX(candidate_votes)FROM candidate_details)" array(1) { [0]=> array(7) { ["id"]=> string(1) "7" ["constituency_id"]=> string(1) "2" ["candidate_name"]=> string(4) "Ravi" ["candidate_party"]=> string(3) "INC" ["candidate_votes"]=> string(6) "879879" ["percentage_votes"]=> string(2) "20" ["elect_year"]=> string(4) "2011" } }
#28

[eluser]toopay[/eluser]
Then, what you mean it not generates right result?

Above function is working, check if 'Ravi' is the Candidate who has max:candidate votes in your table.
#29

[eluser]Bigil Michael[/eluser]
every time it prints revi as the result
if revi has only 10 votes it print revi as the winner
#30

[eluser]toopay[/eluser]
In candidate_details table, what types of candidate_votes? is it string or integer?




Theme © iAndrew 2016 - Forum software by © MyBB