kimjessen Posted January 22, 2015 Share Posted January 22, 2015 Hi Yes I start a new thread, this is probably the correct one. I have solved my problem almost. the result ends with the end of a parenthesis. see picture how do I get it deleted. <?php $dir = './data/test111'; $ddArray1 = scandir($dir,1); ?> <html> <head> <title>Select Drop Down List</title> </head> <body> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <select name="file"> <?php FOREACH($ddArray1 AS $file){ PRINT '<option value="'.$file.'">'.$file.'</option>'; } ?> </select> <input type="submit"/> </form> </body> </html> <?php if ($_POST) { echo '<pre>'; print_r($_POST); $test='</pre>>'; echo $test; } ?> Quote Link to comment Share on other sites More sharing options...
CroNiX Posted January 22, 2015 Share Posted January 22, 2015 So it's showing up after you submit the form? Not sure if it's the forum doing it or your code converting the > to >, but try: if ($_POST) { echo '<pre>'; print_r($_POST); echo '</pre>'; } Quote Link to comment Share on other sites More sharing options...
kimjessen Posted January 22, 2015 Author Share Posted January 22, 2015 (edited) the > are right not a err. yes it did make a difference, not for the better. but a difference is something. the result is here! Array([file] => test111-2015-01-22.csv) now I can almost imagine where the end brackets come from. but how do I get them removed? Moreover, many thanks for the help. Edited January 22, 2015 by kimjessen Quote Link to comment Share on other sites More sharing options...
CroNiX Posted January 22, 2015 Share Posted January 22, 2015 That's because you're printing the whole array using print_r, which stands for "print array". If you want just the file, then do: if ($_POST) { echo $_POST['file']; //only echos the 'file' index from the $_POST array } Quote Link to comment Share on other sites More sharing options...
kimjessen Posted January 22, 2015 Author Share Posted January 22, 2015 hi yes it seemed to me that I had tried it, but I was wrong, now I tried it again and now it works, super thank you Quote Link to comment Share on other sites More sharing options...
kimjessen Posted January 22, 2015 Author Share Posted January 22, 2015 Hello again! It does not work as I expected. I would combine it with the graph, but I only get an error when I press the button. I understand: who is in error description but can it be solved, or do I need to have the graph to run on a page by itself. ? error message looks like this. " Explanation:HTTP headers have already been sent back to the browser indicating the data as text before the library got a chance to send it's image HTTP header to this browser. This makes it impossible for the library to send back image data to the browser (since that would be interpretated as text by the browser and show up as junk text).Most likely you have some text in your script before the call to Graph::Stroke(). If this texts gets sent back to the browser the browser will assume that all data is plain text. Look for any text, even spaces and newlines, that might have been sent back to the browser. For example it is a common mistake to leave a blank line before the opening "<?php". " <?php $dir = './data/test111'; $ddArray1 = scandir($dir,1); ?> <html> <head> <title>Select Drop Down List</title> </head> <body> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <select name="file"> <?php FOREACH($ddArray1 AS $file){ PRINT '<option value="'.$file.'">'.$file.'</option>'; } ?> </select> <input type="submit"/> </form> </body> </html> <?php if ($_POST) { $id=$_POST['file']; //only echos the 'file' index from the $_POST array //echo $id; define("LOG_FILE", "./data/test111/".$id); require_once('jpgraph/src/jpgraph.php'); require_once('jpgraph/src/jpgraph_line.php'); $times = array(); $values = array(); $file_lines = file(LOG_FILE, FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES); foreach($file_lines as $line_num => $line_value) { $line_elements = explode(",", $line_value); $times[] = date($line_elements[0]); $values[] = $line_elements[1]; } $graph = new Graph(800, 400); $graph->SetFrame(false); $graph->SetScale('intint'); $graph->SetMarginColor('white'); $graph->title->Set("Temp midt tank"); $graph->xaxis->SetTickLabels($times); $graph->yaxis->scale->SetAutoMin(0); $graph->yaxis->title->Set("°C"); $graph->ygrid->SetFill($aFlg=true, $aColor1='white', $aColor2='gray9'); $lineplot = new LinePlot($values); $lineplot->SetColor('blue'); $graph->Add($lineplot); $graph->Stroke(); } ?> Quote Link to comment Share on other sites More sharing options...
CroNiX Posted January 22, 2015 Share Posted January 22, 2015 I'm sorry, I don't know anything about that graphing class you're using. Quote Link to comment Share on other sites More sharing options...
kimjessen Posted January 22, 2015 Author Share Posted January 22, 2015 Ok else anyone who has an idea Quote Link to comment Share on other sites More sharing options...
Barand Posted January 22, 2015 Share Posted January 22, 2015 (edited) No guarantees, but try putting the php portion of your code in a separate file (mygraph.php) and use GET instead of post. In a separate php file put $id = whatever; echo "<img src='mygraph.php?file=$id' />"; Edited January 22, 2015 by Barand Quote Link to comment Share on other sites More sharing options...
kimjessen Posted January 22, 2015 Author Share Posted January 22, 2015 hey it works that's what I do today. I would like to have it on the same page. I think that I have to use a different graph library. possibly some java. Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted January 22, 2015 Solution Share Posted January 22, 2015 No problem now we have established that works <?php $dir = './data/test111'; $ddArray1 = scandir($dir,1); ?> <html> <head> <title>Select Drop Down List</title> </head> <body> <form action="" method="get"> <select name="file"> <?php FOREACH($ddArray1 AS $file){ PRINT '<option value="'.$file.'">'.$file.'</option>'; } ?> </select> <input type="submit"/> </form> </body> </html> <?php if (isset($_GET['file'])) { $id = $_GET['file']; echo "<img src='mygraph.php?file=$id' />" ; } ?> Quote Link to comment Share on other sites More sharing options...
kimjessen Posted January 22, 2015 Author Share Posted January 22, 2015 that one i need some further explanation. Quote Link to comment Share on other sites More sharing options...
Barand Posted January 22, 2015 Share Posted January 22, 2015 You said you wanted the chart on the same page Quote Link to comment Share on other sites More sharing options...
kimjessen Posted January 22, 2015 Author Share Posted January 22, 2015 hi guys you are just amazing. It works just as I had hoped for, again many thanks. Now we need to work a little with design and things like that. This forum is great, no question seems too stupid, and being helped, thank you. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.