salamay
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
Also How can I populate the grid with this array?
Regards,
Salamay
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;
}
Also How can I populate the grid with this array?
Regards,
Salamay
SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
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
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
ASKER
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