Hi I am using google organisation charts for my web application in Codeigniter- PHP/Mysql. I have loaded the nodes of my chart from mysql database. And the text in the nodes are made as links. Everything is fine till now. But now I want to add href to the link, so that when user clicks on the link it should navigate to the details page, where the details of particular node is shown. I know, in order to show the details, there should be an Id of the node to fetch the data from database. So here's my question How can I add this id to the link?
Is there any way to do this? Can anyone please help me. Here is my code:
model:
public function getTreeMembersData()
{
$this->db->select('E1.name AS memname,E2.name AS parentname,E3.name AS spouse');
$this->db->from('tab_members AS E1');
$this->db->join('tab_members AS E2', 'E2.member_id = E1.parent_id','left outer');
$this->db->join('tab_members AS E3', 'E3.parent_id = E1.member_id AND E3.relation_id = 3','left outer');
$this->db->where('E1.relation_id !=', 3);
$query = $this->db->get();
return $query->result();
}
Controller:
public function membertree()
{
if(isset($_SESSION['username']) || isset($_SESSION['userid']))
{
$page['pagename'] = "membertree";
$data['msg'] = $this->session->flashdata('msg');
$this->load->view('header',$page);
$data['treedata'] = $this->Family_model->getTreeMembersData();
$this->load->view('membertree',$data);
$this->load->view('footer');
}
else
{
redirect('Auth/login');
}
}
View:
<script type="text/javascript">
var url="<?php echo base_url();?>";
google.charts.load('current', {packages:["orgchart"]});
google.charts.setOnLoadCallback(drawChart);
var data;
var chart;
function drawChart() {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Name');
data.addColumn('string', 'Parent');
data.addRows([<?php
foreach($treedata as $d)
{
$memname = $d->memname;
$parent = $d->parentname;
$spouse = $d->spouse;
?>
[{v:'<?php echo $memname;?>', f:'<a><?php echo $memname;?><a><div><a><?php echo $spouse;?></a></div>'},'<?php echo $parent; ?>'],
<?php
}
?>]);
var options = {
'width':250,
'height':600};
// Create the chart.
var chart = new google.visualization.OrgChart(document.getElementById('chart_div'));
// Draw the chart, setting the allowHtml option to true for the tooltips.
chart.draw(data, {allowHtml:true});
google.visualization.events.addListener(chart, 'select', selectHandler);
function selectHandler() {
var selectedItem = chart.getSelection()[0];
if(selectedItem) {
var name = data.getValue(selectedItem.row,0);
alert(name);
}
}
}
<div class="box">
<div class="box-body">
<div id="chart_div" class="chart"></div>
</div>
</div>
if you are able to get the id from the query,
you can add in the address to the details page as a
'GET'
parameter in thehref
attribute.something like...
as in the data row...