Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From what you've posted in comments, what you have is an array of objects.. not html, as your function seems to indicate. Depending on what you want done, the answer would be either of the following, to access that object's properties:</p> <pre><code>showVotes[0].votes </code></pre> <p>Or</p> <pre><code>showVotes[0]['votes'] </code></pre> <p>Eg:</p> <pre><code>$('#rvotes').html(showVotes[0].votes); </code></pre> <p>Or etc.</p> <p><strong>Second attempt:</strong></p> <p>Firstly, change your current 'showVotes' function to this:</p> <pre><code>function showVotes() { $showresult = mysql_query("SELECT * from mms") or die("Invalid query: " . mysql_error()); while ($row = mysql_fetch_assoc($showresult)) { $response[] = $row; } return json_encode($response); } </code></pre> <p>Secondly, remove your 'connected successfully' text from the page, as well as any other text generated by anything else(aka, the other function which returns a result pointer). I may be wrong, but it would seem to me that the generation of this other text is causing the returned json to be interpreted as malformed.</p> <p><strong>Quick explanation on PDO:</strong></p> <pre><code>try { $dbh = new PDO("mysql:host=localhost;dbname=dbname", "user", "password"); $dbh-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (\PDOException $e) { echo "Error! Could not connect to database: " . $e-&gt;getMessage() . "&lt;br/&gt;"; die(); } </code></pre> <p>Connecting to the database.. This is how I've learned to do it, though I've been warned(and downvoted) to not check for errors this way, though it was never explained why.</p> <p>Database interaction:</p> <pre><code>$stmt = $dbh-&gt;prepare("UPDATE mms SET votes = votes+1 WHERE color = :color"); $stmt-&gt;bindParam(":color",$_POST['color']); $stmt-&gt;execute(); </code></pre> <p>Result use:</p> <pre><code>while ($row = $stmt-&gt;fetch(PDO::FETCH_ASSOC)) { $response[] = $row; } </code></pre> <p>And so on and so forth. PDO escapes the values for you, so you don't have to worry about injection attacks.</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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