RE: pulling data from array

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> -----Original Message-----
> From: Richard Kurth [mailto:richardkurth@xxxxxxxxxxxxxx]
> Sent: Monday, September 08, 2008 1:55 PM
> To: PHP General List
> Subject:  pulling data from array
> 
> I am trying to pass the data from a table to a
> google.visualization.OrgChart javascript
> I have converted the data to an array called $customf_array.
> Look down in the script to where I need to pull the data out of the
> array to see the reset of my question

---8<--- snip!

> <*****************************look at this
> section***********************>
> This is what I do not understand  how to do if you can give me some
> examples on how to sort and pull this data out of the array or if
there
> is a better way to do this
> I have been working with this for a few days and do not no where to go
> 
> This is the section I need to loop through the array and add the data
> it needs to number each recored and the add the members name according
> to the rep# and the managers name according to the  sponserrep#
> $number //the recored number
> $addname // the members name
> $addmanager// the managers name
> 
>         data.setCell($number, 0, '$addname','<h1>$addname</h1>');
>         data.setCell($number, 1, '$addmanager');
> 
> 
> <*****************************l***********************>
> 
>         var table = new
> google.visualization.OrgChart(document.getElementById('chart_div'));
>         table.draw(data, {allowHtml:true});
> }
> 
> </script></head>
> <body><div id="chart_div"></div></body>
> </html>

1.) Sort your data in the SQL query, not with PHP or Javascript. Google
for the "ORDER BY" SQL clause.
2.) Don't cram all the values into an array of strings that are joined
with commas if you're only going to break them back apart and meddle
with them individually (as you are). Just create a simple
object/structure to hold the data you're working with (number, name,
manager's name) and make an array of those. Here's an example:

<?php
class valueObject
{
	var $id, $name, $manager;
}

# assign values to the objects and push them into an array like this:

while($row = mysql_fetch_array($result)) {
	$obj = new valueObject();
	$obj->id = $row['id'];
	$obj->name = $row['firstname'] . $row['lastname'];
	$obj->manager = $row['manager'];
	$objArray[] = $obj;
}

?>

<!-- start your javascript here -->

<script type="text/javascript">
function drawChart()
{
	// init blah blah blah

<?php

# now loop through your object array and translate to js function calls

foreach($objArray as $record) {
	echo "data.setCell(0, 0, '{$row['firstname']}',
'{$row['lastname']}');";
}

?>

}
</script>

...

I hope that helps. Somehow, I don't think you're using the Google Apps
Javascript function ".setCell" properly. I'm guessing the first to
parameters are the cell coordinates, and it's always [0,0] in your loop.
Anyway...


Todd Boyd
Web Programmer

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux