Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It looks like you're missing some curly braces in your for loop. Right now, you've got a 1-line <code>for</code> loop that does nothing but assign a value to your temp variable, which is re-declared on every iteration. I can't remember what the scope rules are for JavaScript in this situation, but it's generally bad practice to do this (if it's intentional). Try something like this for your <code>displayEmployee()</code> method.</p> <pre><code>function displayEmployee(){ for(var i=0; i&lt;details.length; i++) { var temp_details = details[i]; //Display the id, name, and sal. var id = temp_details[0]; var name = temp_details[1]; var sal = temp_details[2]; alert(id); alert(name); alert(sal); } } </code></pre> <p>That should fix your immediate problem. If you have control over all of your code, I'd recommend turning the employee data into an object so it's more manageable. To do this, you should use this PHP code:</p> <pre><code>&lt;?php echo '&lt;script&gt; addEmployee('.json_encode(array( 'id' =&gt; 'id1', 'name' =&gt; 'fname1', 'salary' =&gt; 1024, )).'); addEmployee('.json_encode(array( 'id' =&gt; 'id2', 'name' =&gt; 'fname2', 'salary' =&gt; 2048, )).'); &lt;/script&gt;'; ?&gt; </code></pre> <p>And then alter your JavaScript code to look like this:</p> <pre><code>var details = []; function addEmployee(employeeObj){ details[details.length] = employeeObj; alert(employeeObj); } function displayEmployee(){ for(var i=0; i&lt;details.length; i++) { alert(details[i].id); alert(details[i].name); alert(details[i].salary); } } </code></pre> <p>I haven't tested this code, but it should run.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload