So, I am trying to get all my rows out of my database, and then be able to list and manipulate them within javascript. So far, all my research as pointed me towards objects.
This is my code so far:
<?php
if($_SESSION['username']) {
$sql = "SELECT * FROM potentials";
$result = mysql_query($sql) or die(mysql_error());
$potential = mysql_fetch_array($result);
$array = array();
while ($row = mysql_fetch_assoc($result)) {
$array[] = $row;
}
$myJSON = json_encode($array);
echo $myJSON;
?>
And my javascript:
<script type="text/javascript">
$(document).ready(function(){
var potentialModels = <?php print($myJSON); ?>;
console.log(potentialModels);
});
</script>
I get this returned in the console:
[Object]
0: Object
length: 1
__proto__: Array[0]
but shouldnt it be:
Object {Models: Array[2]}
Models: Array[2]
0: Object
address: "407 Forby Estates Dr "
age: ""
city: "Eureka"
dayofweek: ""
email: "rebekahkeller@yahoo.com"
firstname: "Maddie"
id: "54"
joindate: "2013-04-09 16:25:38"
lastname: "Keller"
parentname: "Rick Bross"
parentnumber: "0"
phone: "6367511428"
state: "MO"
timeofday: "after 9:30 am"
twitter: ""
zip: "63025"
__proto__: Object
1: Object
length: 2
__proto__: Array[0]
__proto__: Object
Should I be using aforeach instead of a while loop in my PHP statement?
Once I have all the rows in objects (or an array of objects? idk!?!?), how do I retrieve the values?