Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You are mixing up Java and JavaScript. For example this is Java syntax, you can't write this within a script tag which should only contain JavaScript:</p> <pre><code>string [][] hhgdata = new string[numrows][4]; </code></pre> <p>The JavaScript arrays are dynamic, this should be enough:</p> <pre><code>var hhgdata = []; </code></pre> <p>When you want to add another array into it, as you seem to be doing later in your code, just do this:</p> <pre><code>hhgdata[counter] = []; </code></pre> <p>And then assign to the inner array:</p> <pre><code>hhgdata[counter][1] = hhgtitle; </code></pre> <p>You are also creating multiple assigning an unquoted string literal to variable with this (assuming <code>$hhgtitle</code> contains a string):</p> <pre><code>hhgtitle = &lt;?php echo $hhgtitle; ?&gt;; </code></pre> <p>It should be something like this:</p> <pre><code>hhgtitle = &lt;?php echo '"' . $hhgtitle .'"'; ?&gt;; </code></pre> <p>Finally, while it's not incorrect, your PHP <code>while</code> loop is creating multiple <code>script</code> elements in your HTML.</p> <h2><strong>EDIT</strong></h2> <p>I have made the changes described above as well as in comments, copy-paste exactly and see how it goes:</p> <pre><code>&lt;body&gt; &lt;?php $con = mysql_connect("XXXXXX.COM","guest","password"); mysql_select_db("HHG", $con); if (!$con) { die('Could not connect: ' . mysql_error()); } else { $result = mysql_query("SELECT * FROM articles", $con); $numrows = mysql_num_rows($result); echo "DB connection OK &lt;br/&gt;"; echo "Found "; echo $numrows; echo " records &lt;br/&gt;&lt;br/&gt;"; } // EVERYTHING WORKS UP TO HERE ?&gt; &lt;script type="text/javascript"&gt; document.write("THIS IS THE FISRT JS DOING SOMETHING"); // THIS DOES NOTHING numrows = &lt;?php echo $numrows; ?&gt;; // THIS DOES NOTHING var hhgdata = new Array(numrows); // THIS DOES NOTHING document.write("Records = " + numrows + "&lt;br/&gt;"); // THIS DOES NOTHING &lt;/script&gt; &lt;?php $counter = 1; while ($row = mysql_fetch_assoc($result)) { echo $row["idimg"]; echo "&lt;br/&gt;"; //THIS WORKS $hhgtitle = $row["hhgtitle"]; //THIS WORKS echo $hhgtitle; echo "&lt;br/&gt;"; //THIS WORKS ?&gt; &lt;script type="text/javascript"&gt; //THIS WORKS var counter = &lt;?php echo $counter; ?&gt;; //THIS WORKS document.write("counter = " + counter); //THIS WORKS hhgtitle = &lt;?php echo '"' . $hhgtitle . '"'; ?&gt;; // THIS DOES NOTHING document.write("Title: "); // THIS DOES NOTHING hhgdata[counter] = []; hhgdata[counter][1]= hhgtitle; // THIS DOES NOTHING document.write("&lt;br /&gt;hhgdata[counter][1]: " + hhgdata[counter][1]); // THIS DOES NOTHING &lt;/script&gt; &lt;?php $counter++; // THIS WORKS } ?&gt; &lt;/body&gt; </code></pre>
 

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