Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7661141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:33:32+00:00 2026-05-31T13:33:32+00:00

I think this is a case of me not knowing javascript, but I can’t

  • 0

I think this is a case of me not knowing javascript, but I can’t for the love of god get this to work

For some reason, creating vars cancels out my java alert code. (maybe bc its wrong)
And my java vars aren’t being set correctly.

I pointed out the problems in my comments

In my SQL, I have Temperatures all with an associative value disk ‘id’.
So my data structure in this is:

$array[id];
$array[id]=array();
//For every new element
//Using while ($row = mysql_fetch_assoc($result)) 
$array[id][]="temperature";

//second id
$array[id2];
$array[id2]=array();
//For every new element
$array[id2][]="temperature";
$array[id2][]="temperature2";
$array[id2][]="temperature3";
$array[id2][]="temperature4";

MY ATTEMPT (WRONG CODE):
//I simplified this code down. In my own version, the join works ONLY when I use an actual index “174” instead of a javascript variable that is 174. Couldnt get join to be alerted in this simplified version

<?php
$phparray=array();
$phparray["100"]="First Element";
$phparray["101"]="Second Element";
$phparray["102"]="Third Element";

$phparray["100"]=array();
$phparray["101"]=array();
$phparray["100"][]="First Element - Sub 2";
$phparray["100"][]="First Element - Sub 3";
$phparray["101"][]="Second Element - Sub 2";


echo $phparray["100"];  //Does not show 'First Element'. Shows Array
echo $phparray["100"][0];   //Correctly shows sub element
//var_dump($phparray);


?>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Associative Array in PHP used in Java Test</title>

        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
        <script type="text/javascript">

var index=100;
//var index2=<?php echo $phparray[index]; ?>; //Supposed to output 'First Element'
var joined=[<?php echo join($phparray[index], ', '); ?>];   //Supposed to join elements of '100'

alert("hello");  //This line does not work anymore after the var index2 made above
        </script>
    </head>
    <body>

<div id="container" style="height: 500px; min-width: 600px"></div>
    </body>
</html>

EDIT: Here is the long full code of my php page:

<?php 
include_once("../../config.php"); 
$conn=mysql_connect($dbhost,$dbuser,$dbpasswd) or die ('Error connecting to mysql');
mysql_select_db($dbname);

ini_set('error_reporting', E_ALL);
//ini_set('display_errors',1);
ini_set('log_errors',1);

$sql = "select disk_id from disk";
$result = mysql_query($sql);
$ids = array();
$names=array();
$temperatures = array();
while ($row = mysql_fetch_assoc($result)) {
   $ids[] = $row['disk_id'];
    $temperatures[]=$row['disk_id'];
    //echo "<br>".$row['disk_id'];
}
//

foreach ($ids as $value)
{
//echo "--START ".$value."--<br>";
$sql = "select * from disk_data WHERE disk_id=".$value;
$result = mysql_query($sql);
$dates=array();
    $key = array_search($value, $temperatures);
    $temperatures[$value] = array();

//var_dump($temperatures);
while ($row = mysql_fetch_assoc($result)) 
{   
    $temps = $row['Temperature'];
    $temp = explode("||", $temps);
    $prehex=$temp[3];
    $posthex=hexdec(substr($prehex,-2));

    $predate=$row['create_date'];
    $postdate =strtotime($predate)*1000;


    $output="[".$postdate.", ".$posthex."]";
    //$temperatures[$key][] = $output;
    $temperatures[$value][] = $output;


    $dates[]=$row['create_date'];
    //echo $row['create_date']." ".end($temperatures[$key])."<br>";
}
}

print_r(array_keys($array));
var_dump($temperatures);
foreach ($ids as $value)
{
    //echo $value;
    $key = array_search($value, $temperatures);

    //echo "Key: $key; Value: $temperatures[$value]<br />\n";
    $comma = join($temperatures[$value],", ");
    echo $comma;
    echo "\n";
}



?>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Highstock Example</title>

        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
        <script type="text/javascript">

$(function() {
    var seriesOptions = [],
        yAxisOptions = [],
        seriesCounter = 0,




        //names=[<?php echo join($ids, ', '); ?>],
        names=["174"], //Above code works. BUT only using ID 174 to test
        values=[<?php echo join($temperatures["174"], ', '); ?>], //Supposed to be ALL data. But temp 174
        colors = Highcharts.getOptions().colors;
    //alert(values);

    $.each(names, function(i, name2) {
//alert(seriesOptions.length);
alert(name2.toString()); //Works....
var values=[<?php 
echo join($temperatures[name2], ', '); ?>]; //Doesnt work
//alert(values);
console.log(values);
//document.write(values);


            seriesOptions[i] = 
            {
                name: name2,
                data:values

            };

            // As we're loading the data asynchronously, we don't know what order it will arrive. So
            // we keep a counter and create the chart when all the data is loaded.
            seriesCounter++;

            if (seriesCounter == names.length) 
            {
                createChart();
            }

    });



    // create the chart when all data is loaded
    function createChart() {

        chart = new Highcharts.StockChart({
            chart: {
                renderTo: 'container'
            },

            rangeSelector: {
                selected: 0
            },

                title: {
                    text: 'Test Performance Data',
                    style: {        
                margin: '10px 100px 0 0' // center it   
                }           
        },


            yAxis: {
            title: {text:'Temperature (°C)'}, 
                labels: {
                    formatter: function() {
                        return this.value + '';
                    }
                },
                plotLines: [{
                    value: 0,
                    width: 2,
                    color: 'silver'
                }]
            },

            plotOptions: {
            line: {
                gapSize: 0
            },
                series: {
                    //compare: 'percent'
                }
            },

            tooltip: {
                pointFormat: '<span style="color:{series.color}">{series.name}</span>: <b>{point.y}</b> ({point.change}%)<br/>',
                yDecimals: 2
            },

            series: seriesOptions
        });
    }

});
        </script>
    </head>
    <body>
<script type="text/javascript" src="../js/highstock.js"></script>
<script type="text/javascript" src="../js/themes/gray.js"></script>
<div id="container" style="height: 500px; min-width: 600px"></div>
    </body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T13:33:32+00:00Added an answer on May 31, 2026 at 1:33 pm

    You cannot mix PHP and JavaScript like that. JavaScript variables are not parsed in PHP.
    Even when index is replaced by a variable $index or 100, your code would still miss quotes.

    Use the following instead:

    <script type="text/javascript">
    var index=100;
    var array = <?php echo json_encode($phparray); ?>;
    var joined = array[index];
    

    The last line outputs the following:

    var joined={"100":["First Element - Sub 2","First Element - Sub 3"],"101":["Second Element - Sub 2"],"102":"Third Element"};
    

    Before trying this, make sure that you remove the invalid comment in the line after var index = 100;. Otherwise, a PHP warning can be generated, which invalidates the code:

    var index=100;
    //var index2=PHP Notice:  Use of undefined constant index - assumed 'index' in /tmp/t.php on line 29
    PHP Notice:  Undefined index: index in /tmp/t.php on line 29
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think this is a simple question, but I can not find the answer
I think this is pretty much the simplest case for mapping a Map (that
I think this is likely to be a generic .NET assembly loading question, but
i think this is a bit of a noob question, but here goes. I
I think this is going to be one of those simple-when-you-see-it problems, but it
I think this question needs some code: private TypeValues GetEnumValues(Type enumType, string description) {
So this is more of a question due to not knowing the right word,
Hey all, I think this might be a bug, but it's killing me. I
I'm using the iPhone SDK 3.0, but I think this is a general misunderstanding
Do you think this code close correctly the output stream entry ? Knowing that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.