Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble getting array back from JSON call to SQL
    primarykey
    data
    text
    <p>Just trying to grab everything from a table "guesses" sorted by "cnt" and turn it into a javascript array. Can't get it to give me anything I can work with, though.</p> <p>PHP file:</p> <pre><code>&lt;?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'root'; $dbname = 'words'; $dbtable = 'guesses'; //------ DATABASE CONNECTION --------// mysql_connect($dbhost,$dbuser,$dbpass) or die ("Unable to connect to database"); mysql_select_db($dbname) or die ("Unable to select database"); $sql = "SELECT * FROM $dbtable ORDER BY cnt ASC"; $result = mysql_query($sql); while($array = mysql_fetch_assoc($result)) { echo json_encode($array); } ?&gt; </code></pre> <p>JavaScript:</p> <pre><code> $.getJSON('grab.php', function(response) { // response is a JSON object that contains all the info from sql query // tried so much stuff here... no avail. console.log(response); }) </code></pre> <p>The console doesn't say anything. "SELECT * FROM guesses ORDER BY cnt ASC" in the phpmyadmin console DOES return the correct entries and order.</p> <p>EDIT: I've also tried</p> <pre><code>&lt;?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'root'; $dbname = 'words'; $dbtable = 'guesses'; //------ DATABASE CONNECTION --------// mysql_connect($dbhost,$dbuser,$dbpass) or die ("Unable to connect to database"); mysql_select_db($dbname) or die ("Unable to select database"); $sql = "SELECT * FROM $dbtable ORDER BY cnt ASC"; $result = mysql_query($sql); while($array = mysql_fetch_assoc($result)); echo json_encode($array); ?&gt; </code></pre> <p>Which might be syntactically better(???) but it returns "false" to console, and nothing else.</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.
 

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