Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

In a php file, I have a function that finds the most recent txt file and sets it as a variable $filesb to be parsed out:

    $dir = "../geo-05/Hassayampa/";
    if($dir) chdir($dir);
    $filesb = glob('{Graph}*.{txt}', GLOB_BRACE);
    usort($filesb, create_function('$e, $f', 'return filemtime( $f ) - filemtime ( $e );')   
    );
    for ($i = 0; $i < $show; ++$i)
    $dir.$filec = $filesb[$i];

further down the page I have my Highcharts graph in <script> tags. In the $.get tag I've inserted:

$.get('<?php echo $filesb[0]?>', function(data){ 

but the data from the array $filesb does not graph. Does the javascript function not recognize the array? It does work when I point to the file directly:

$.get('http://www.geoinc.org/monitor/SiteData/Data/geo-05/Hassayampa/Graph_telemetry_140626.txt', function(data){ 

The reason I don't have it pointing at the file directly is because the file name changes, so if I set it to be $filesb it will always find the most recent file. I apologize if I am unclear, I am new to coding.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

Try this:

 $.get('<? echo $filesb ?>', function(data){ 
share|improve this answer
    
I think I'm still doing something wrong, I've included the index file in my question above with your suggested change? Do you see anything obviously wrong, I've been staring at this for hours. –  tonystinge Jun 26 at 16:26
    
OK, I see you are using <?php instead of just <? to delimit PHP code. Try doing '<?php echo $filesb ?>' instead. –  HaukurHaf Jun 26 at 16:30
    
i tried that :) –  tonystinge Jun 26 at 16:31
    
Ok ... view the source of the page. What is being output in the source? $.get(' <what is here ?> ') –  HaukurHaf Jun 26 at 16:38
    
Okey, so you have an array called $filesb and another variable called $fileb which supposedly contains the filename of a single file? Then do this instead $.get('<? echo $fileb ?>', function(data){ .... Of course you cannot output an array like that, you'd have to iterate trough the array and output this for every element in the array. –  HaukurHaf Jun 26 at 17:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.