Strange mysql result

Game development with Board Game Arena Studio
Post Reply
EnergyBear
Posts: 3
Joined: 13 March 2017, 07:22

Strange mysql result

Post by EnergyBear »

Hi !

I have a table with that structure :

Code: Select all

CREATE TABLE IF NOT EXISTS `tfs_gameboard_tiles` (
  `position_h` int(1) NOT NULL,
  `position_v` int(1) NOT NULL,
  `card_id` int(10) DEFAULT NULL,
  `properties` text,
  `player_id` int(10) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
It is harvested with that data:

Code: Select all

INSERT INTO `tfs_gameboard_tiles` (`position_h`, `position_v`, `card_id`, `properties`, `player_id`) VALUES
(0, 1, NULL, NULL, NULL),
(0, 2, NULL, NULL, NULL),
(0, 3, NULL, NULL, NULL),
(1, 0, NULL, NULL, NULL),
(1, 1, NULL, NULL, NULL),
(1, 2, NULL, NULL, NULL),
(1, 3, NULL, NULL, NULL),
(1, 4, NULL, NULL, NULL),
(2, 0, NULL, NULL, NULL),
(2, 1, NULL, NULL, NULL),
(2, 2, NULL, NULL, NULL),
(2, 3, NULL, NULL, NULL),
(2, 4, NULL, NULL, NULL),
(3, 0, NULL, NULL, NULL),
(3, 1, NULL, NULL, NULL),
(3, 2, NULL, NULL, NULL),
(3, 3, NULL, NULL, NULL),
(3, 4, NULL, NULL, NULL),
(4, 1, NULL, NULL, NULL),
(4, 2, NULL, NULL, NULL),
(4, 3, NULL, NULL, NULL);
But, with the SQL query

Code: Select all

self::getCollectionFromDb("SELECT * FROM tfs_gameboard_tiles")
, I have this result:

Code: Select all

array(5) {
  [0]=>
  array(5) {
    ["position_h"]=>
    string(1) "0"
    ["position_v"]=>
    string(1) "3"
    ["card_id"]=>
    NULL
    ["properties"]=>
    NULL
    ["player_id"]=>
    NULL
  }
  [1]=>
  array(5) {
    ["position_h"]=>
    string(1) "1"
    ["position_v"]=>
    string(1) "4"
    ["card_id"]=>
    NULL
    ["properties"]=>
    NULL
    ["player_id"]=>
    NULL
  }
  [2]=>
  array(5) {
    ["position_h"]=>
    string(1) "2"
    ["position_v"]=>
    string(1) "4"
    ["card_id"]=>
    NULL
    ["properties"]=>
    NULL
    ["player_id"]=>
    NULL
  }
  [3]=>
  array(5) {
    ["position_h"]=>
    string(1) "3"
    ["position_v"]=>
    string(1) "4"
    ["card_id"]=>
    NULL
    ["properties"]=>
    NULL
    ["player_id"]=>
    NULL
  }
  [4]=>
  array(5) {
    ["position_h"]=>
    string(1) "4"
    ["position_v"]=>
    string(1) "3"
    ["card_id"]=>
    NULL
    ["properties"]=>
    NULL
    ["player_id"]=>
    NULL
  }
}
Do you know if the BGA framework is rewriting my query (with a limit somewhere) ?

Thanks guys!
User avatar
docthib
Posts: 73
Joined: 10 August 2015, 14:05

Re: Strange mysql result

Post by docthib »

Hi,

It looks like the query took one of each 'position_h' value as key and last entry with same 'position_h' as value.

Seems like a 'normal' behaviour for self::getCollectionFromDB( $sql, $bSingleValue=false )
See doc

For the result you want, I guess you need to add a unique ID to your table or use the self::DbQuery() function
User avatar
Morgalad
Posts: 108
Joined: 17 January 2017, 20:46
Contact:

Re: Strange mysql result

Post by Morgalad »

It is easier than you think, you need to add a key to the table

use this to the create table stament

Code: Select all

CREATE TABLE IF NOT EXISTS `tfs_gameboard_tiles` (
  `row_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `position_h` int(1) NOT NULL,
  `position_v` int(1) NOT NULL,
  `card_id` int(10) DEFAULT NULL,
  `properties` text,
  `player_id` int(10) DEFAULT NULL,
   PRIMARY KEY (`row_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Cheers...
Morgalad

Developer of: Incan Gold , Takara Island , Taluva and Veggie Garden
Post Reply

Return to “Developers”