1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Select an area and query database

Discussion in 'Facepalm' started by XdmingXD, Aug 13, 2017.

  1. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    158
    GitHub:
    xdmingxd
    Hello...
    PHP:
    if($X1 $X2 && $Z1 $Z2) {
                for(
    $x $X1 $x $X2 $x++) {
                    for(
    $z $Z1 $z $Z2 $z++) {
                        
    $query $this->getDatabase()->prepare("SELECT date,time,player,x,y,z,event,block FROM database WHERE x='$x' AND z='$z' ");
                        
    $result $query->execute();
                        
    $this->data $this->fetchall($result);
                        
    var_dump($data); //return array(0) {}
                    
    }
                }
    var_dump($data); //return array(0) { }
    Thanks
     
    Last edited: Aug 13, 2017
  2. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    1. Very laggy. You are executing a lot of database queries (($X2 - $X1 + 1) * ($Z2 - $Z1 + 1) queries).
    2. Undefined variable. I don't see definition of $data anyway.
    3. No idea what you are asking. What's wrong?
    4. Unknown method. What is $this->fetchall()?
    5. Unknown method. What is $this->getDatabase()? I have no idea what your database returns.
     
  3. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    158
    GitHub:
    xdmingxd
    Sorry :(
    My brain just can't work today
    PHP:
    //Copy form a plugin :P
    public function fetchall($result){
    $row = array();
    $i 0;
    while(
    $res $result->fetchArray(SQLITE3_ASSOC)){
    $row[$i] = $res;
    $i++;
    }
    return 
    $row;
    }

    public function 
    getDatabase() {
         return 
    $this->database;
    }

    //tpying error not $this->data but $data
    if($X1 $X2 && $Z1 $Z2) {
    for(
    $x $X1 $x $X2 $x++) {
    for(
    $z $Z1 $z $Z2 $z++) {
    $query $this->getDatabase()->prepare("SELECT date,time,player,x,y,z,event,block FROM ServerLog WHERE x='$x' AND z='$z' ");
    $result $query->execute();
    $data $this->fetchall($result);
    }
    }
    var_dump($data); //$data return array(0) {} but doesn't contain any value?
    }
    }
     
  4. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    And did you make sure your ServerLog table is not empty?

    And don't put your query in a for loop. Did you know that there is an SQL operator called "less than"?
     
  5. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    158
    GitHub:
    xdmingxd
    Really?Oh my word...No...lol
    Thx fixed
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.