Welcome Guest, Not a member yet? Register   Sign In
quick question on 'math' in codeigniter
#1

[eluser]Unknown[/eluser]
I have a quick question about CodeIgniter. A couple years back, in PHP/ADOdb411, I created a system that allowed fans of a soccer team to come the site and rate the players on their performance 1-10, then display the average rating.

The way I had it structured was I had the following tables in MySQL: player, game, rating. The rating table had the rating value, but also had foreign keys for the player and the game. Then whenever the games page was displayed I'd set my query to AVG(rating_value) as average_rating for each player.

Is this possible to do in CodeIgniter? Is there a better way than I did it previously?
#2

[eluser]Pachirulo[/eluser]
Everything is possible with CI but, i think u are using SQL not PHP to do an average.

I think the better way is doing AVG at SQL, I think is always faster.
#3

[eluser]Unknown[/eluser]
[quote author="Pachirulo" date="1214332253"]Everything is possible with CI but, i think u are using SQL not PHP to do an average.

I think the better way is doing AVG at SQL, I think is always faster.[/quote]

you're right, i meant that i was doing AVG in my SQL query, not in the PHP.

i'll have to do some digging now to find out how to use the AVG in the SQL query with CI. any tips on what section(s) to pay close attention to?
#4

[eluser]Pachirulo[/eluser]
yes, at user guide... or you can use something like
Code:
$this->db->query('select * from mytable... etc etc');

take a look here: http://ellislab.com/codeigniter/user-gui...index.html
#5

[eluser]xwero[/eluser]
$this->db->select_avg();

See Active Record page




Theme © iAndrew 2016 - Forum software by © MyBB