Jump to content

Destramic

Members
  • Posts

    969
  • Joined

  • Last visited

Everything posted by Destramic

  1. ummm seems a bit long winded...but maybe the only option i have...thank you...is there way of setting a static property without it being defined as a property?...cause that would help haha
  2. ok cool thanks...so how would i do it if i wanted to do something like this $var = 'mysql'; $this->$var = DB::factory($db_type, array('host' => $db_host, 'username' => $db_username, 'password' => $db_password, 'database' => $db_name), $db_table); cause i wouldnt know what the property name would be...
  3. hey guys here is my model which extended from every News_Model, User_Model etc. the problem im facing is with the line $this->mysql = DB::factory($db_type, array('host' => $db_host, 'username' => $db_username, 'password' => $db_password, 'database' => $db_name), $db_table); becasue when defying the $this->mysql property it sets in the __set magic method which i dont want...but i need the $this->mysql property to be stored in the model class so it can be used in the __call and __set methods. so basically somehow i wanna set $this->msyql without going troube the magic method __set <?php class Model { public function __construct() { $config = Registry::singleton()->config; $db_type = $config->db_type; $db_host = $config->db_host; $db_username = $config->db_username; $db_password = $config->db_password; $db_name = $config->db_name; $db_table = $this->get_table_name(); $this->mysql = DB::factory($db_type, array('host' => $db_host, 'username' => $db_username, 'password' => $db_password, 'database' => $db_name), $db_table); } public function __set($column, $value) { $this->mysql->$column = $value; } public function __call($method, $arguments) { if (method_exists($this->mysql, $method)) { $this->mysql->$method($arguments); } } protected function get_table_name() { $config = Registry::singleton()->config; $model_name = get_class($this); $model_prefix = $config->model_prefix; $prefix_length = strlen($model_prefix); $table_name = substr($model_name, 0, - $prefix_length); $table_name = strtolower($table_name); $table_name = Inflection::pluralize($table_name); return $table_name; } } how it will then be used to update columns Class News_Model { } Class Some_Controller { $news = new News_Model(); $news->status = 1; $news->save(3); // will update news column status where id = 3 } if anyone can help me please...i can't think how to tackle this
  4. well the way i was thinking of doing is was loading the controller and action though the front controller...and i dunno how your framework operates but you could just include the controller like: $news = new News_Controller(); $news->articles() //retutning all the aticles i dont know if this is a good way of doing things but it would work nicely in my framework
  5. that worked great...thanks mate
  6. hey guys im having a problem with finding out if i string has the followeing... a-z, 0-9, /, _, - and white spaces...im not sure why it is returning false when the charters in the $uri variable are allowed characters...maybe a expression problem if anyone can help please on shy its not working...thank you <?php protected function is_uri_friendly($uri) { $uri = "game/counter-strike/league/test"; if (preg_match('#[^a-z0-9/-_]#i', $uri) > 0) { echo "$uri contain invalid characters\n"; }else { echo "$uri DOES NOT contain invalid characters.\n"; } ?> }
  7. hey guys ive been making and designing my own framwork which isnt far off completion now...im just wondering...do other frameworks have like a action/method which allows you to call another controller in a controller? so bascially in your index page your able to call your news headline, voting poll, search etc...? thanks guys
  8. thanks for your help guys
  9. ive used trim to get rid of the end of a a string and it takes an extra character off it anyone can help please $class_name = "League_Model"; echo $model_name = trim($class_name, "_Model"); result: Leagu im want it to return: league
  10. sorry no markup in the cotroller?
  11. ok thanks note taken...so should i just do the loop update in the controller would that be correct?
  12. 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
  13. thanks for your post thorpe...can i load the controller method in the template to have a update in a loop?
  14. 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
  15. fenway you are the main man...thanks alot
  16. 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`
  17. 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?
  18. 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?
  19. 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
  20. 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
  21. 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
  22. 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
  23. 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
  24. oh sorry that is where i should have a date column?...im still trying to design this table
  25. 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
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.