-
Posts
960 -
Joined
-
Last visited
Everything posted by Destramic
-
calling a model method in view template
Destramic replied to Destramic's topic in Application Design
sorry no markup in the cotroller? -
calling a model method in view template
Destramic replied to Destramic's topic in Application Design
ok thanks note taken...so should i just do the loop update in the controller would that be correct? -
calling a model method in view template
Destramic replied to Destramic's topic in Application Design
maybe this will help you to understand what im trying to do template where i want to update in loop <table> <tr> <th id="rank">Rank</th> <th id="team">Team</th> <th id="points">PTS</th> <th id="matches_played">MP</th> <th id="wins">W</th> <th id="losses">L</th> <th id="draws">D</th> <th id="streak">W Streak</th> </tr> <?php foreach ($this->rows as $rows):?> // update row in loop <tr> <td><?= $rows['rank'] ?>.</td> <td><?= $rows['team_name'] ?></td> <td><?= $rows['points'] ?></td> <td><?= $rows['matches_played'] ?></td> <td><?= $rows['wins'] ?></td> <td><?= $rows['losses'] ?></td> <td><?= $rows['draws'] ?></td> <td><?= $rows['win_streak'] ?></td> </tr> <?php endforeach; ?> </table> or should i just create a loop in my controller of $this->rows and do the updates there?....if you could tell me what the best practice would be plesase -
calling a model method in view template
Destramic replied to Destramic's topic in Application Design
thanks for your post thorpe...can i load the controller method in the template to have a update in a loop? -
heys guys just a simple question...bascially in my model i have a method that get rows from a table and those rows are presented in my template file in a loop. now what i wanna do is have a update in the loop its self to change column values of that particular row...how can i do this really? it is ok to somehow call the model in the template file? $this->news->update_status($val, $val2); i be happy if someone could help me on this question...thank you
-
fenway you are the main man...thanks alot
-
sorry you are gonna have to bear with me and explain a bit more cause im no pro with mysql wrap max()? aslso i tried IFNULL(@win_streak, 0) but it didnt work. and you want me to get rid of the case? MAX(@win_streak := CASE lmr.result WHEN 'Win' THEN @win_streak +1 ELSE 0 END) AS `win_streak`
-
yeah i suppose i could put if (empty($row['win_steak'])) { echo "0"; } else { echo $row['win_streak']; } but i'd much prefer to be able to do it in the query...and what do you mean by crazy query? haha...i mean how else should i do what i want to do in a query?
-
why what other way do you think i should do it?...but like i said some of the teams have no records of matches and they havent had any so the win_streak reutrns null....can i set that to 0 somehow please?
-
ok ive got it working now finnaly...the only problem i do have if you can help is that the win_streak column returns null on some cases...not ive tried to put WHEN NULL THEN 0 in the case but that doesnt do nothing...still returns null...thanks for your help fenway SET @rank := 0; SET @points := 0; SET @tie := 0; SET @win_streak := 0; SELECT *, @rank := IF(@points = points, IF(@points = '0', @rank + 1, @rank), @rank + 1), @points := points, @tie := IF(@points = points, IF(@points = '0', @tie = '0', @tie = '1'), @tie = '0'), IF(@tie = '1', @rank + 1, @rank) as rank, @tie := '0' FROM( SELECT t.team_id, t.team_name, (SELECT MAX(@win_streak := CASE lmr.result WHEN 'Win' THEN @win_streak +1 ELSE 0 END) FROM league_match_results lmr LEFT JOIN league_matches lm ON lm.league_match_id = lmr.league_match_id WHERE lmr.team_id = t.team_id ORDER BY lm.date DESC) AS `win_streak`, COUNT(r.league_match_result_id) AS 'matches_played', SUM(IF(r.result='Win', 1, 0)) AS `wins`, SUM(IF(r.result='Loss', 1, 0)) AS `losses`, SUM(IF(r.result='Draw', 1, 0)) AS `draws`, SUM(IF(r.result='Win', 3, IF(r.result='Draw', 1, IF(r.result='Loss', 0, 0)))) AS `points` FROM teams t LEFT JOIN league_match_results r ON r.team_id = t.team_id LEFT JOIN team_leagues tl ON tl.team_id = t.team_id LEFT JOIN leagues l ON l.league_name = 'Counter-Strike Europeon Team Death Match' LEFT JOIN games g ON g.game_abbreviation = 'CSS' GROUP BY t.team_id ORDER BY points DESC, t.team_name) AS x
-
ok i sort of go in work...but...it returns the team as having 1 streak...but it has no win result if you can help please SELECT MAX( IF( lmr.result = 'Win', @win_streak +1, IF( lmr.result = 'Draw', @win_streak = '0', IF( lmr.result = 'Loss', @win_streak = '0', @win_streak = '0' ) ) ) ) AS `win_streak` FROM league_match_results lmr LEFT JOIN league_matches lm ON lm.league_match_id = lmr.league_match_id WHERE lmr.team_id =1 ORDER BY lm.date DESC
-
thanks fenway...a very useful site...now ive tried to do what i think is right but the query isnt working at all the error im getting is SET @rank := 0; SET @points := 0; SET @tie := 0; SET @win_streak := 0; SELECT *, @rank := IF(@points = points, IF(@points = '0', @rank + 1, @rank), @rank + 1), @points := points, @tie := IF(@points = points, IF(@points = '0', @tie = '0', @tie = '1'), @tie = '0'), IF(@tie = '1', @rank + 1, @rank) as rank, @tie := '0', @win_streak := '0' FROM( SELECT t.team_id, t.team_name, (SELECT IF(lmr.result='Win', @win_streak + 1, IF(lmr.result='Draw', @win_streak = '0', IF(lmr.result='Loss', @win_streak = '0', 0))) AS `win_streak` FROM league_match_results lmr LEFT JOIN league_matches lm ON lm.league_match_id = lmr.league_match_id WHERE lmr.team_id = t.team_id ORDER BY lm.date DESC), COUNT(r.league_match_result_id) AS 'matches_played', SUM(IF(r.result='Win', 1, 0)) AS `wins`, SUM(IF(r.result='Loss', 1, 0)) AS `losses`, SUM(IF(r.result='Draw', 1, 0)) AS `draws`, SUM(IF(r.result='Win', 3, IF(r.result='Draw', 1, IF(r.result='Loss', 0, 0)))) AS `points` FROM teams t LEFT JOIN league_match_results r ON r.team_id = t.team_id LEFT JOIN team_leagues tl ON tl.team_id = t.team_id LEFT JOIN leagues l ON l.league_name = 'test' LEFT JOIN games g ON g.game_abbreviation = 'CSS' GROUP BY t.team_id ORDER BY points DESC, t.team_name) AS x the query works without (SELECT IF(lmr.result='Win', @win_streak + 1, IF(lmr.result='Draw', @win_streak = '0', IF(lmr.result='Loss', @win_streak = '0', 0))) AS `win_streak` FROM league_match_results lmr LEFT JOIN league_matches lm ON lm.league_match_id = lmr.league_match_id WHERE lmr.team_id = t.team_id ORDER BY lm.date DESC), can you please help me
-
well this is the query i have been working on and yeah the query from the same topic....and sorry yes that table now has a date included now
-
sorry about the delay... here is the query i have and i want to add a streak column to it so if you can help or advise me what to do...i would like to add it to this query really if possible SET @rank := 0; SET @points := 0; SET @drawing := 0; SELECT *, @rank := IF(@points = points, IF(@points = '0', @rank + 1, @rank), @rank + 1), @points := points, @drawing := IF(@points = points, IF(@points = '0', @drawing = '0', @drawing = '1'), @drawing = '0'), IF(@drawing = '1', @rank + 1, @rank) as rank, @drawing := '0' FROM( SELECT t.team_id, t.team_name, COUNT(r.league_match_result_id) AS 'matches_played', SUM(IF(r.result='Win', 1, 0)) AS `wins`, SUM(IF(r.result='Loss', 1, 0)) AS `losses`, SUM(IF(r.result='Draw', 1, 0)) AS `draws`, SUM(IF(r.result='Win', 3, IF(r.result='Draw', 1, IF(r.result='Loss', 0, 0)))) AS `points` FROM teams t LEFT JOIN league_match_results r ON r.team_id = t.team_id LEFT JOIN team_leagues tl ON tl.team_id = t.team_id LEFT JOIN leagues l ON l.league_name = 'test' LEFT JOIN games g ON g.game_abbreviation = 'CSS' GROUP BY t.team_id ORDER BY points DESC, t.team_name) AS x
-
oh sorry that is where i should have a date column?...im still trying to design this table
-
what im basical after is the current continuous streak...so if a team has won thier last 3 games then streak is 3...but if they loss or draw then the streak ends and equals 0
-
sorry i dont see what you mean by sortorder column?...you mean the column i want to sort and order?
-
hey guys i have a table called match_results and looks like this match_results -------------------------- league_result_id league_match_id team_id result ------------------------- now what i want to be able to do is when selecting the results is get the steak where result = win if anyone could help or have a site on how this can be done please...thank you
-
this is what i wanted call_user_func_array(array(new $name(), "__construct"), $arguments);
-
im using my own framework im building...now ive decided to go down the root of using helpersin my view class public function __call($helper, $arguments) { if (!$this->get_helper($helper)) { $instance = new $helper($arguments); $this->set_helper($helper, $instance); return $instance; } } now the __call works as i want it...but the problem is the $arguments var is an array and gets sent to the helper like that...what is the best way to tackle this...i'd like it to be send as a string as it is not a array (i think the __call method automatically makes the incoming string an array) if you could give me your help/suggestions please guys
-
ok but calling $this->_title inside the template isnt exactly right is it?
-
@nightsylr i decided to do it like you said... public function league($game_name, $league_name) { $rows = $this->leagues->fetch_league($game_name, $league_name); $this->view->head_title('test - hello'); $this->view->rows = $rows; $this->view->render('headers/header.html'); $this->view->render('leagues/league.html'); $this->view->render('footers/footer.html'); } if that is how you meant...now when the title is set it will assign the value to $this->_title ... but i dont want the title called like that in my header file...is there a way i can do this without changing the property name?
-
ok i see now thank you...so what would be the best way to do this and include the header and footer to each controller?
-
the problem im getting is with this line in the bootstrap $this->view->head_title('test'); the view property is only initiated in the league_controller and $this->view doesnt exsist within the bootstap but i call the bootstrap header in the league controller and it wont let me execute the head title...if anyone can help me on why or how i can over come this please....thank you (code below) bootstrap public static function header() { $this->view->head_title('test'); } leaugue_controller method public function league($game_name, $league_name) { Bootstrap::header(); $rows = $this->leagues->fetch_league($game_name, $league_name); $this->view->head_title()->set_separator()->prepend('hello'); $this->view->rows = $rows; Bootstrap::footer(); }
-
my bad...but can you tell me if it is good or bad practice to use them the way i said?