Search Results

Search found 3 results on 1 pages for 'noko'.

Page 1/1 | 1 

  • MySQL stuck on "using filesort" when doing an "order by"

    - by noko
    I can't seem to get my query to stop using filesort. This is my query: SELECT s.`pilot`, p.`name`, s.`sector`, s.`hull` FROM `pilots` p LEFT JOIN `ships` s ON ( (s.`game` = p.`game`) AND (s.`pilot` = p.`id`) ) WHERE p.`game` = 1 AND p.`id` <> 2 AND s.`sector` = 43 AND s.`hull` > 0 ORDER BY p.`last_move` DESC Table structures: CREATE TABLE IF NOT EXISTS `pilots` ( `id` mediumint(5) unsigned NOT NULL AUTO_INCREMENT, `game` tinyint(3) unsigned NOT NULL DEFAULT '0', `last_move` int(10) NOT NULL DEFAULT '0', UNIQUE KEY `id` (`id`), KEY `last_move` (`last_move`), KEY `game_id_lastmove` (`game`,`id`,`last_move`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ; CREATE TABLE IF NOT EXISTS `ships` ( `id` mediumint(5) unsigned NOT NULL AUTO_INCREMENT, `game` tinyint(3) unsigned NOT NULL DEFAULT '0', `pilot` mediumint(5) unsigned NOT NULL DEFAULT '0', `sector` smallint(5) unsigned NOT NULL DEFAULT '0', `hull` smallint(4) unsigned NOT NULL DEFAULT '50', UNIQUE KEY `id` (`id`), KEY `game` (`game`), KEY `pilot` (`pilot`), KEY `sector` (`sector`), KEY `hull` (`hull`), KEY `game_2` (`game`,`pilot`,`sector`,`hull`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ; The explain: id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE p ref id,game_id_lastmove game_id_lastmove 1 const 7 Using where; Using filesort 1 SIMPLE s ref game,pilot,sector... game_2 6 const,fightclub_alpha.p.id,const 1 Using where; Using index edit: I cut some of the unnecessary pieces out of my queries/table structure. Anybody have any ideas?

    Read the article

  • PHP Game weapon accuracy

    - by noko
    I'm trying to come up with a way for players to fire their weapons and only hit for a certain percentage. For example, one gun can only hit 70% of the time while another only hits 34% of the time. So far all I could come up with is weighted arrays. Attempt 1: private function weighted_random(&$weight) { $weights = array(($weight/100), (100-$weight)/100); $r = mt_rand(1,1000); $offset = 0; foreach($weights as $k => $w) { $offset += $w*1000; if($r <= $offset) return $k; } } Attempt 2: private function weapon_fired(&$weight) { $hit = array(); for($i = 0; $i < $weight; $i++) $hit[] = true; for($i = $weight; $i < 100; $i++) $hit[] = false; shuffle($hit); return $hit[mt_rand(0,100)]; } It doesn't seem that the players are hitting the correct percentages but I'm not really sure why. Any ideas or suggestions? Is anything glaringly wrong with these? Thanks

    Read the article

  • PHP PDO Parameters from a function returned array

    - by noko
    I've got a function written that runs a query based on parameters passed to the function. I can't seem to figure out why doing the following returns a result: function test($function_returned_array) { $variable = 'Hello World'; $sql = 'SELECT `name`, `pid` FROM `products` WHERE `name` IN (?)'; $found = $this->db->get_array($sql, $variable); } While this doesn't return any results: function test2($function_returned_array) { $sql = 'SELECT `name`, `pid` FROM `products` WHERE `name` IN (?)'; $found = $this->db->get_array($sql, $function_returned_array[0]); } $function_returned_array[0] is also equal to 'Hello World'. Shouldn't they both return the same results? When I echo the values of $variable and $function_returned_array[0], they are both 'Hello World' Here's the relevant parts of my PDO wrapper: public function query(&$query, $params) { $sth = $this->_db->prepare($query); if(is_null($params)) { $sth->execute(); } else if(is_array($params)) { $sth->execute($params); } else { $sth->execute(array($params)); } $this->_rows = $sth->rowCount(); $this->_counter++; return $sth; } public function get_array(&$query, $params, $style = PDO::FETCH_ASSOC) { $q = $this->query($query, $params); return $q->fetchAll($style); } I'm using PHP 5.3.5. Any help would be appreciated.

    Read the article

1