*I know MYSQL is depricated. I am just using it as a learning tool for now.
UPDATED QUESTION:
I updated my question to make a lil more sense...
How can I display the output array (json data in PHP file) on my HTML page assuming I wanted to add it to the div id rvotes?
JavaScript
<script>
$(document).ready(function () {
$('.answer').click(function (e) {
var color = $(this).attr("data-color");
$.ajax({
type: 'POST',
url: 'mm.php',
data: { color: color},
dataType: 'json',
cache: false,
success: function(showVotes) {
$('#rvotes').html(row[0]);
},
error: function (jqXHR) {
}
})
})
});
</script>
PHP
function showVotes()
{
$sql = "SELECT * FROM mms";
$result = mysql_query($sql) or die(mysql_error());
$showresult = mysql_query("SELECT * from mms") or die("Invalid query: " . mysql_error());
$response = array();
while($row = mysql_fetch_assoc($showresult))
$results[] = $row;
echo json_encode($results);
}
ADDING my HTML code
<div id="wrapper">
<div id="red" data-color="red" class="answer">
<a href="#"><img src="images/red.jpg" width="100%" /></a>
</div>
<div id="blue" data-color="blue" class="answer">
<a href="#"><img src="images/blue.jpg" width="100%" /></a>
</div>
<div id="green" data-color="green" class="answer">
<a href="#"><img src="images/green.jpg" width="100%" /></a>
</div>
<div id=rvotes>
TEST
</div>
<div id=bvotes>
TEST
</div>
How can I display the output from the array back at my HTML page?