Jump to content

Destramic

Members
  • Posts

    969
  • Joined

  • Last visited

Everything posted by Destramic

  1. in fact ive been having a little reading about it and im no expert yet but something like this i need if you can help....bare in mind it obviously dont work $query = 'SELECT name, dob FROM users ORDER BY dob DESC '; $replace = "WHERE name = 'destramic'"; $test = preg_replace('(FROM)\s[a-zA-Z0-9](.*)(ORDER\S+BY)', $replace, $query); generate this: SELECT name, dob FROM users WHERE name = 'destramic' ORDER BY dob DESC
  2. but the thing is the name of the table could be anything. so... SELECT name, dob FROM users ORDER BY dob DESC needs to have WHERE name = 'destramic' added into the string to complete the sql query SELECT name, dob FROM users WHERE name = 'destramic' ORDER BY dob DESC i hope you understand
  3. well i want to be able to insert WHERE name = 'destramic' inbetween SELECT name, dob FROM users and ORDER BY dob DESC but i want to do it using regex but i dont know how to do it...so im after the help please
  4. hey guys...basically i have a query which looks like: SELECT name, dob FROM users ORDER BY dob DESC but what i want to do is to get this string and place WHERE name = 'destramic' inbetween FROM users and ORDER BY dob DESC using regex so that it looks like SELECT name, dob FROM users WHERE name = 'destramic' ORDER BY dob DESC can someone please help me....thanks you
  5. does the registry class just read a text file with config options?
  6. thanks alot
  7. interesting...but would it be wise to have a model class which is extended by league_model class which does the mysql connection?
  8. im trying to get a match on the pattern that will look like :game, :league, :whatever ...etc... but the script below will only find 1 match when there should be 2...can anyone please help? <?php $pattern = "game/:game/league/:league"; if (preg_match_all('/(?<=\w+/', $pattern, $matches)) { foreach ($matches as $match) { echo $match_count = count($matches); } } ?>
  9. below is my model and how it looks...im wondering if that is how it should be done exactly?...i mean is it right that i should have to type my config details in everytime?...should i just get these details passed from a .config file containg the db name, host, username and password? if i could have some advise on this please thank you <?php class League_Model { public function fetch_all() { $config = array('host' => 'localhost', 'username' => 'root', 'password' => 'test', 'database' => 'test'); $db = DB::factory('MySQL', $config); $db->connect(); $variables = array('rank' => '0', 'points' => '0', 'drawing' => '0'); $query = "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 WHERE tl.league_id = :1 GROUP BY t.team_id ORDER BY points DESC, t.team_name) AS x"; $league = $db->set($variables)->fetch_all($query, '1'); $rows = $league->get_rows(); return $rows; } public function fetch_row() { } }
  10. well i suppose i could do it in a constuctor
  11. echo get_class($this); did the trick...but how can i call a method if the class is an extended class
  12. hey guys...is there a way of getting the name of that class that the extended class was called from...ie. <?php class News_Controller etends Actions { } class Actions { public function model_name() { $model_name // = class name news_controller } } ?>[code] [/code]
  13. model i meant sorry...although i believe modules are good to use?
  14. interesting guys thank you for your help...regarding modules?...should i just have a one module class that executes the connection of the database for controller?
  15. thank you that is a intresting site...i dont tend to use other script but just ideas...i like everything i use to be created by me so i know i fully understand the system/script...im trying to create my own framework of a project i have... this is what the page controllers will look like...let me know what you think and if you have any ideas please...thank you again <?php class Leagues_Controller extends Action { public function leagues() { } public function league($game) { $config = array('host' => 'localhost', 'username' => 'root', 'password' => '', 'database' => ''); $db = DB::factory('MySQL', $config); $db->connect(); $variables = array('rank' => '0', 'points' => '0', 'drawing' => '0'); $query = "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 WHERE tl.league_id = :1 GROUP BY t.team_id ORDER BY points DESC, t.team_name) AS x"; $league = $db->set($variables)->fetch_all($query, '1'); $rows = $league->get_rows(); $view = new View; $view->rows = $rows; $view->title('')->add_css('')->add_js('')->add_template(''); } }
  16. but i dont think a orm could produce a complex query as above
  17. i see...but how would you do such a complex query such as : $team_select = "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 WHERE tl.league_id = :1 GROUP BY t.team_id ORDER BY points DESC, t.team_name) AS x"; using that method?
  18. im having a problem with executing this query if anyone can help me please SET @rank := 0; SET @points := 0; SET @drawing := 0; @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;
  19. hey guys i see alot of sql patterns designed where you have a method for every sql command eg. $sql = new SQL $sql->select('news, date')->from('news')->execute(); but that all seems too complex...what im asking why isnt sql classes made not as simple as $sql = new SQL $sql->query('SELECT news, date FROM news')->execute(); would the way above be more easier?
  20. ive tried this simple script and its not coming true...for some reason it doesnt search the first key if anyone can help please? $array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red'); $key = array_search('blue', $array); if ($key) { echo hi; }
  21. hey guys i have a little problem if you could help please... basiclally my request will get a uri and try and break it up into controller, action and parameters but when a uri request is made like: game/counter-strike/leagues http://localhost/game/counter-strike/leagues it may not actually be a direct route and need rerouting with the router. now what i want to do is create a function which will get the game which is counter-strike...in this case the array looks like Array ( [0] => game [1] => counter-strike [2] => leagues ) now i dont know if this is the correct way of getting the value...but would i be able to search for 'game' as if it exists could i get the next array. i hope you understand and can maybe help....thanks
  22. hey guys im looking for design advice on my framework im trying to design...but im a bit stuck on how the routing should work. the code you will see below...basically you can create a route in the bootstrap and when the framework is executed to run it will see if the uri is a match to a route....now this is were i dunno what to do. 1. should the routing system pass the controller/action and parameters to the request then passed to the dispatcher for dispatching 2. or should the controller/action and parameters be passed straight to the dispatcher to be dispatched? well if someone could help me on which design pattern would be better and give me some advise i'd be very happy...thanks <?php class Router { protected $_uri_variable = ":"; protected $_routes = array(); protected $_request = null; public function __construct() { } public function add_route($pattern, array $route) { $this->_routes[$pattern] = $route; } public function is_route($uri) { $routes = $this->_routes; foreach ($routes as $pattern => $route) { if (array_key_exists('controller', $route)) { $controller = $route['controller']; unset($route['controller']); } if (array_key_exists('action', $route)) { $action = $route['action']; unset($route['action']); } $parameters = $route; if (preg_match_all('/(?<=\w+/', $pattern, $matches)) { foreach ($matches as $match) { $count = count($matches); for ($i = 0; $i < $count;) { $find = $match[$i]; $i++; } if (array_key_exists($find, $parameters)) { $value = $parameters[$find]; if (substr($value, 0, 1) == ':') { // get from request parameters; //$this->_request->get_parameter($find); } else { $pattern = str_replace(':' . $find, $value, $pattern); } } } } if ($uri == $pattern) { return true; } else { return false; } } } } $router = $front_controller->get_router(); $router->add_route('game/:game/leagues', array('controller' => 'leagues', 'action' => 'leagues', 'game' => 'counter-strike'));
  23. after a long stuggle i admit defeat...it comes back saying Error. Access is denied. but i have logged in as administrator as you've said...help please
  24. Sorry about the delay...yes it's just a development machine and only used for just that purpose...but at the moment i'm just using xp...and i'm just viewing the site on localhost
  25. ok well im new to shell commands and i have to say im a bit stuck on how to do this...bear in mind im using apache 2.2 from a windows OS do i need to execute the command with shell_exec()?
×
×
  • 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.