<?php

//connect to the database
$dbconn = pg_Connect("host=capstone06.cs.pdx.edu dbname=real user=postgres password=bees");
if (!$dbconn) {
    die("Error connecting to database.");
}

echo('{"graphs":[');

$result = pg_exec($dbconn, "SELECT COUNT(subgraph_id) FROM subgraphs;");
$rows = pg_fetch_array($result, 0);
$num = $rows[0];

for ($i = 1; $i < $num; $i++) {
    $result = pg_exec($dbconn, "SELECT num FROM subgraphs WHERE subgraph_id = $i;");
    $count = pg_numrows($result);
    if ($count <= 0) {
	die("Bad query at $i");
    }
    $array = pg_fetch_array($result, 0);
    if ($i > 1) {
	echo(', ');
    }
    echo('{"subgraph_id": ' . $i . ', "num": ' . $array[0] . '}');
}

echo('] }');

pg_close($dbconn);

<?php

//connect to the database
$dbconn = pg_Connect("host=capstone06.cs.pdx.edu dbname=real user=postgres password=bees");
if (!$dbconn) {
    die("Error connecting to database.");
}

//there is no subgraph_id 0
echo('{"subgraphs":[0,');

$result = pg_exec($dbconn, "SELECT COUNT(subgraph_id) FROM subgraphs;");
$rows = pg_fetch_array($result, 0);
$num = $rows[0];

for ($i = 1; $i < $num; $i++) {
    $result = pg_exec($dbconn, "SELECT num FROM subgraphs WHERE subgraph_id = $i;");
    $count = pg_numrows($result);
    if ($count <= 0) {
	die("Bad query at $i");
    }
    $array = pg_fetch_array($result, 0);
    if ($i > 1) {
	echo(', ');
    }
    echo($array[0]);
}

echo('] }');

pg_close($dbconn);

--- 
+++ 
@@ -6,8 +6,7 @@
     die("Error connecting to database.");
 }
 
-//there is no subgraph_id 0
-echo('{"subgraphs":[0,');
+echo('{"graphs":[');
 
 $result = pg_exec($dbconn, "SELECT COUNT(subgraph_id) FROM subgraphs;");
 $rows = pg_fetch_array($result, 0);
@@ -23,7 +22,7 @@
     if ($i > 1) {
 	echo(', ');
     }
-    echo($array[0]);
+    echo('{"subgraph_id": ' . $i . ', "num": ' . $array[0] . '}');
 }
 
 echo('] }');
Revert "Redundant information is redundant."

This reverts commit ed9224a57ac396f62d75d1111d4a3be2927b1695.
