<?php
include("regDBConnect.php");
// collect all the results
$rows = array();
$result1 = mysql_query("SELECT * FROM Phase where Pid = 1", $db) or die("cannot select");
while($row = mysql_fetch_array($result1)) {
$rows []= array(
'id' => $row['id'],
'parent' => $row['parent'],
'name' => $row['name'],
);
/*
if you remove the line above and uncomment this instead,
javascript objects will see all the properties you selected from the DB
*/
// $rows []= $row;
}
?>
<script type="text/javascript">
// now output the collected results
var treeData = <?php echo json_encode($rows); ?>;
</script>
Bemærk at det jeg sagde om PDO/MySQLi stadig gælder, dette er blot et minimalt eksempel for at besvare dette specifikke spørgsmål. (Og generelt bør du kun VÆLGE de kolonner, du skal bruge, ikke *
.)