[Firebug-cvs] firebug/web/demo db_print_table.php,NONE,1.1 graphem.php,NONE,1.1
Brought to you by:
doolin
From: David M. D. <do...@us...> - 2004-04-02 00:30:38
|
Update of /cvsroot/firebug/firebug/web/demo In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15440/demo Added Files: db_print_table.php graphem.php Log Message: Worked on graphing web app. --- NEW FILE: db_print_table.php --- <?php ///* echo "<table class=\"db_schema\">"; $statement = "show columns from $tblname;"; $columns = mysql_query($statement) or die("Error: ".mysql_error()." getting columns"); // Build the table header column names. Make this into a function. if ($columnname = mysql_fetch_array($columns)) { print("<tr>\n"); $names = array(); do { print ("<td>"); array_push($names, $columnname[0]); print $columnname[0]; print ("</td>"); } while ($columnname = mysql_fetch_array($columns)); print("</tr>\n"); // This is pretty cool for debugging. //print_r($names); } $statement = "select * from $tblname"; $result = mysql_query($statement); function print_table_row($item2,$key) { print ("<td>\n"); echo "$item2\n"; print ("</td>\n"); } if ($row = mysql_fetch_row($result)) { do { print ("<tr>"); $row = array_values($row); array_walk($row,'print_table_row'); print ("</tr>"); } while ($row = mysql_fetch_row($result)); } echo "</table>"; //*/ ?> --- NEW FILE: graphem.php --- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>Results demo script</title> <link rel="SHORTCUT ICON" href="../images/favicon.ico"> <link type="text/css" rel="stylesheet" href="../firebug.css"> </head> <body> <h1>Demonstration monitoring</h1> <?php $dbname = "gpsradio"; $tblname = "location"; //$dbname = $HTTP_POST_VARS["db1"]; //$tblname = $HTTP_SESSION_VARS["tblname"]; //$checkboxname = $HTTP_SESSION_VARS["cb"]; $radiox = $HTTP_POST_VARS["radiox"]; $radioy = $HTTP_POST_VARS["radioy"]; $xmin = $HTTP_POST_VARS["xmin"]; $xmax = $HTTP_POST_VARS["xmax"]; //echo "Radio x: ".$radiox;echo "Radio y: ".$radioy; mysql_connect("localhost","root","") or die("Error: ".mysql_error()." in mysql_connect."); $dblink=mysql_select_db("$dbname") or die("Error: ".mysql_error()." in mysql_select_db."); ?> <?php //include "db_print_table.php"; ?> <form action="graphem.php" method="post"> <table> <tr> <td>mote_id</td> <td><input type=radio name=radiox value="mote_id"</td> <td><input type=radio name=radioy value="mote_id"</td> </tr> <tr> <td>gps_hours</td> <td><input type=radio name=radiox value="gps_hours"</td> <td><input type=radio name=radioy value="gps_hours"</td> </tr> <tr> <td>gps_minutes</td> <td><input type=radio name=radiox value="gps_minutes"</td> <td><input type=radio name=radioy value="gps_minutes"</td> </tr> <tr> <td>gps_seconds</td> <td><input type=radio name=radiox value="gps_seconds"</td> <td><input type=radio name=radioy value="gps_seconds"</td> </tr> <tr> <td>lat_deg</td> <td><input type=radio name=radiox value="lat_deg"</td> <td><input type=radio name=radioy value="lat_deg"</td> </tr> <tr> <td>lat_dec_min</td> <td><input type=radio name=radiox value="lat_dec_min"</td> <td><input type=radio name=radioy value="lat_dec_min"</td> </tr> <tr> <td>long_deg</td> <td><input type=radio name=radiox value="long_deg"</td> <td><input type=radio name=radioy value="long_deg"</td> </tr> <tr> <td>long_dec_min</td> <td><input type=radio name=radiox value="long_dec_min"</td> <td><input type=radio name=radioy value="long_dec_min"</td> </tr> <tr> <td>nsew</td> <td><input type=radio name=radiox value="nsew"</td> <td><input type=radio name=radioy value="nsew"</td> </tr> <tr> <td>numsats</td> <td><input type=radio name=radiox value="numsats"</td> <td><input type=radio name=radioy value="numsats"</td> </tr> </table> <input type=hidden name=db1 value="dbname"> <input type=submit value="Plot"> </form> <?php $dbname = "gpsradio"; $statement = "use $dbname"; mysql_query($statement) or die("Error: ".mysql_error()." changing databases"); if ($radioy == null) { print("Error, must choose a y value\n"); // statement for selecting against y value only. } if ($radiox == null) { $statement = "select $radioy from location where lat_deg = 37 and long_deg = 122"; } else { $statement = "select $radiox,$radioy from location where lat_deg = 37 and long_deg = 122"; } $result = mysql_query($statement) or die("Error: ".mysql_error()." in select statement"); if (!$ofp=fopen("test.dat","w")) { echo "Unable to open data output file for writing.\n"; } if(!chmod ("test.dat", 0775)) { echo "chmod failed\n"; } function print_row($item2,$key) { fwrite($ofp,$item2); } if ($row = mysql_fetch_row($result)) { // for each row do { // For each column... $row = array_values($row); $size = count($row); for ($i=0; $i<$size; $i++) { // This is no good for multiple columns. fwrite($ofp,$row[$i]." "); } fwrite($ofp,"\n"); } while ($row = mysql_fetch_row($result)); } fclose($ofp); // This stuff doesn't work yet, but would be // be a better way to do this. Move all this // kind of stuff into dedicated functions. //$command = "echo -e 'set term png\n"; $command = "'set term png\n"; $command .= "set size 0.4\n"; //$command .= "plot \"test2.dat\"\n'"; $command .= "plot \"test.dat\"\n'"; //$command .= "| C:/gp373w32/pgnuplot.exe > test.png"; $command .= "| C:/gp373w32/pgnuplot.exe > test.png"; //$plotcommand = "echo -e 'set term png\n"; $plotcommand = "'set term png\n"; $plotcommand .= "set size 0.4\n"; $plotcommand .= "set output \"test.png\"\n"; $plotcommand .= "plot \"test.dat\" with lines 2'"; $plotstring = "set term png\n"; $plotstring .= "set size 0.8\n"; $plotstring .= "set output \"test.png\"\n"; $plotstring .= "plot \"test.dat\" with lines 2"; $gnuplot = " | C:\\gp373w32\\pgnuplot.exe"; //echo $command; // System call $systemcall = $plotcommand; $systemcall .= $gnuplot; $gnufile = "test2.gnu"; //$ofp = fopen("test1.gnu","w"); $ofp = fopen($gnufile,"w"); fwrite($ofp,$plotstring); fclose($ofp); //system("C:\\gp373w32\\pgnuplot.exe < ./test1.gnu"); //Try the redirect going the other way with an output file name. system("C:\\gp373w32\\pgnuplot.exe < ./$gnufile"); // > $outfile.png /* print("<pre>"); print($plotcommand.$gnuplot); print("</pre>"); */ //This doesn't work either. //`$plotcommand.$gnuplot`; /* $systemcall = $plotcommand; $systemcall .= $gnuplot; $e = escapeshellcmd($systemcall); // This would be preferable, but doesn't seem to work. if(system("echo -e $systemcall",$error)) { echo "System call succeeded\n"; } else { echo "System call failed with error $error\n"; } print("<pre>"); print($e); print("</pre>"); */ echo "<center>"; echo "<img src=\"test.png\">"; echo "</center>"; ?> <?php include("../nav_footer.php"); //$radiox = null; //$radioy = null; ?> <hr /> <p> Last Updated: $Date: 2004/04/02 00:18:36 $ by $Author: doolin $. </p> </body> </html> |