Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End How do i foreach items into my boxes?

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #277178
    martinnorlund
    Participant

    (I dont know why my first topic got removed so i am trying again)

    As my title saids i have a problem with foreaching database items into some boxes that also is in my database. So what i am trying to do is receive my items with same id as the box into it.
    Right now my boxes makes duplicates for as many items i got + some of the items arent even the same id as the box.

    This is the code i got right now.

    HTML/PHP

    https://codepen.io/anon/pen/YJXQrx
    

    SQL

    <?php
    class Home extends DB {
    
      private $db;
    
      public function __construct() {
        $this->openDB();
      }
    
      public function getLocations() {
        $this->query("SELECT sg_location.location_id, sg_projects.location_id, sg_location.loc_name, sg_projects.proj_name, sg_projects.proj_project, sg_projects.proj_description FROM sg_location
          LEFT JOIN sg_projects ON (sg_location.location_id = sg_projects.location_id)
          WHERE sg_location.location_id=1
          ORDER BY sg_location.location_id DESC");
        return $this->resultset();
      }
    
      public function getItems() {
        $this->query("SELECT sg_projects.*
            FROM sg_projects
            LEFT JOIN sg_location ON (sg_location.location_id = sg_projects.location_id)
            WHERE sg_projects.location_id=1
            ORDER BY sg_projects.project_id DESC");
        return $this->resultset();
      }
    
    
    }
    

    Database

    table1: sg_location (boxes)
    location_id
    loc_name
    
    table2: sg_projects (items)
    project_id
    proj_name
    proj_project
    proj_description
    location_id
    

    Hope there is a clever head out there that knows how to do this :)

    #277184
    martinnorlund
    Participant
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Back End’ is closed to new topics and replies.