Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

SQLite SELECT

Comments in 'Plugin Development' started by wolfdale, Jul 21, 2015.

  1. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    I have multiple records, shown in the picture below, i want to list down all records where the owner is Ghost_Ge
    [​IMG]
    My code is:
    PHP:
    $target "Ghost_Ge"
    $chests =  $db->query("SELECT * FROM chests WHERE owner = \"$target\"")->fetchArray(SQLITE3_ASSOC);
    vardump($chest);
    however, the output only shows the first record:

    Code:
    array(7) {
      ["id"]=>
      int(960)
      ["owner"]=>
      string(8) "Ghost_Ge"
      ["x"]=>
      int(138)
      ["y"]=>
      int(70)
      ["z"]=>
      int(148)
      ["attribute"]=>
      int(0)
      ["passcode"]=>
      string(0) ""
    }
    
    Am i doing something wrong?
    Any help would be apprecited :)
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    fetchArray only returns one row. You need to save the result of $db->query(), and fetchArray on it until fetchArray returns false (hint: use a while loop).
    wolfdale likes this.
  3. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    OMG that does the trick! Thank you so much :)
  4. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    How does sqllite even work? lol

Share This Page

Advertisement