Jump to content

jontilt

New Members
  • Posts

    3
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

jontilt's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi there, I have written a recursive function that basically generates a tree structure for my site pages (kind of like a sitemap). It all worked fine until yesterday, I started getting error messages telling me that I have exhausted the amount of memory available. There are only about 30 pages in the site (parent, child, sub-child etc), so I dont think that I should be using up that much memory. This was my first attempt at a recursive function so I am pretty sure that it may not have been optimised properly. If anyone could take a look and offer any feed back that would be great. (written in codeigniter framework) function getAllPages() { $this->tmp_arr = array(); $this->buildPageStructure(0, 0); return $this->tmp_arr; } function buildPageStructure($parent_id, $counter) { $CI = & get_instance(); $query = $CI->db->query("SELECT page_id, title, page_url, status FROM pages WHERE parent_page='$parent_id' ORDER BY sort_order ASC"); $counter++; if($query->num_rows() > 0) { foreach($query->result() as $row) { $new_arr = new Page(); $new_arr->page_id = $row->page_id; $new_arr->title = $row->title; $new_arr->level = $counter; $new_arr->page_url = $row->page_url; $new_arr->status = $row->status; $this->tmp_arr[] = $new_arr; $this->buildPageStructure($row->page_id, $counter); } } } Cheers Jon
  2. Hi all, I have managed to solve it, so thought I would post the answer just incase anyone else had the same problem. function select_metrics($start_date, $end_date, $location_id) { $query = "SELECT * FROM xxx WHERE Date BETWEEN '$start_date' AND '$end_date' AND xxx = '$location_id'"; $result = mysql_query($query) or die(mysql_error()); $data = array(); $master = array(); $data_two = array(); $master_two = array(); while( $row=mysql_fetch_assoc($result) ) { $time = explode(':', $row['Time']); $data = array($time[0], $row['LAeq']); array_push($master, $data); $data_two = array($time[0], $row['LAE']); array_push($master_two, $data_two); } $menu['metric1'] = array( label => "Metric 1", data => $master, ); $menu['metric2'] = array( label => "Metric 2", data => $master_two, ); echo json_encode($menu); } Cheers Jon
  3. Hi there, I have written an array of data so that it json_encodes into the correct format required for a charting component that I am using. The php array looks like this: First Number = hours Second Number = data $menu['metric1'] = array( label => "Metric 1", data => array( array ('00',48), array ('01',47), array ('02',45), array ('03',40), array ('04',42), array ('05',48), array ('06',38), array ('07',28), array ('08',40), array ('09',30), array ('10',38), array ('11',28), array ('12',18), ) ); $menu['metric2'] = array( label => "Metric 2", data => array( array ('00',30), array ('01',44), array ('02',35), array ('03',49), array ('04',32), array ('05',47), array ('06',38), array ('07',23), array ('08',30), array ('09',34), array ('10',38), array ('11',20), array ('12',31), ) ); When I json encode this, it is represented as this which is perfect. { "metric1": { "label":"Metric 1", "data":[["00",48],["01",47],["02",45],["03",40],["04",42],["05",48],["06",38],["07",28],["08",40],["09",30],["10",38],["11",28],["12",18]] }, "metric2": { "label":"Metric 2", "data":[["00",30],["01",44],["02",35],["03",49],["04",32],["05",47],["06",38],["07",23],["08",30],["09",34],["10",38],["11",20],["12",31]] } } What I am trying to do now is to create that php array from a database, so I have loaded the data into my DB, I have run the correct select statement to extract my data . . . . . and this is where I am now stuck. How would I code up my db result set to form my multidimensional array????? Any help would be greatly appreciated . . . .going a little mad trying to figure this out. Cheers Jon
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.