Link to home
Start Free TrialLog in
Avatar of salamay
salamayFlag for United States of America

asked on

How to populate advanceddatagrid with hierarchical data using php and MySQL?

Following is the hierarchy supposed to go in the grid

Project 1
         Well 1
         Well 2
         Well 3
Project 2
         Well 4
         Well 5
Project 3
         Well 6
         Well 7
         Well 8


I have two tables Projects and Wells in my db with a fk in wells table relating to the project_id

Projects table
project_id       project_name
1                     Project 1
2                     Project 2
3                     Project 3

Wells table
well_id           well_name        projects_project_id
1                     Well 1               1
2                     Well 2               1
3                     Well 3               1
4                     Well 4               2
5                     Well 5               2
6                     Well 6               3
7                     Well 7               3
8                     Well 8               3

I want to modify the following function to get hierarchical data
 
public function getAllProjectsAndWells() {

		$stmt = mysqli_prepare(
					$this->connection, "SELECT project_id, project_name, well_name 
					FROM projects, wells 
					WHERE projects.project_id = wells.projects_project_id");		
		$this->throwExceptionOnError();
		
		mysqli_stmt_execute($stmt);
		$this->throwExceptionOnError();
		
		$rows = array();
		
		mysqli_stmt_bind_result($stmt, $row->project_id, $row->project_name, $row->well_name);
		
	    while (mysqli_stmt_fetch($stmt)) {
	      $rows[] = $row;
	      $row = new stdClass();
	      mysqli_stmt_bind_result($stmt, $row->project_id, $row->project_name, $row->well_name);
	    }
		
		mysqli_stmt_free_result($stmt);
	    mysqli_close($this->connection);
	
	    return $rows;
	}

Open in new window


Also How can I populate the grid with this array?

Regards,
Salamay
SOLUTION
Avatar of xterm
xterm

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of salamay

ASKER

xterm,

I need to store the result in array with the hierarchy and use that to populate the advanceddatagrid in flex. So using your technique how would it be possible to form such an array?

Regards,
Faraz Mir
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of salamay

ASKER

Thanks Xterm.

These are very nice implementations and easy to follow. However flex advanced data grid has its own hierarchy creation using actionscript and i believe that's the only way it can be done.

Regards,
Salamay