Skip to content

Instantly share code, notes, and snippets.

@juniorb2ss
Created November 12, 2013 17:27
Show Gist options
  • Save juniorb2ss/7435067 to your computer and use it in GitHub Desktop.
Save juniorb2ss/7435067 to your computer and use it in GitHub Desktop.
<?php
/**
* why this variable $result?
*/
$result = array();
$rs = mysql_query("select * from dados where id=1");
while($row = mysql_fetch_array($rs))
{
$node = array();
$node['id'] = $row['id'];
$node['text'] = $row['nome_cliente'];
$node['state'] = 'closed';
$node['children'] = has_child(3);
/**
* why this variable $result?
*/
array_push($result,$node);
}
echo json_encode($result);
function has_child($id2){
/**
* why this variable $result?
*/
$result2 = array();
$rs = mysql_query("select id from dados where id = $id2");
$row = mysql_fetch_array($rs);
if($row === FALSE)
{
die('invalid id argument to has_child');
}
return $row[0];
}
@juniorb2ss
Copy link
Author

output: [{"id":"1","text":"ds","state":"closed","children":"2"}]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment