views:

44

answers:

1
foreach($scraperSites as $site) {

    //$scraperWriter->addSite( new ScraperSite($site) );
    print_r($site);

}

scraperSites is the array of all sites from the mySQL database; I'm trying to keep $site as an array, (but only with one row worth of data), add it to an object, then move on to the next row.

A: 

After looking at your code, I think this is your problem:

public static function getScrapedSites($db) {

    $query = "select * from sites";
    $result = $db->query($query);
    $scrapedSites = $result->fetch_assoc();

    return $scrapedSites;

}

I believe this will always return a single row. You need to loop over the results with fetch_assoc() and append the results to an array.

public static function getScrapedSites($db) {

    $query = "select * from sites";
    $result = $db->query($query);

    $scrapedSites = array();

    foreach($result->fetch_assoc() as $site) {
      $scrapedSites[] = $site;
    }

    return $scrapedSites;
}

You said that $site was outputting a string in your example. This is because your foreach loop was iterating over the db fields in the associative array.

Mike B
Thanks :) Obvious mistake, I've been concentrating so much on learning OOP that I've forgotten some basic principles.
RichardHarrington