Here's a question that has me stumped and seeking help.
Following an ajax send request, I utilized this php code to retrieve all the rows and columns from my database:
$sql = "SELECT * FROM categories";
$result=$conn->query($sql);
$arr = $result->fetch_all(MYSQLI_ASSOC);
print_r($arr)
This resulted in the following output:
Array ( [0] => Array ( [cat_id] => 1 [cat_name] => Friends [checkbox] => checked ) [1] => Array ( [cat_id] => 2 [cat_name] => Favourites [checkbox] => checked ) [2] => Array ( [cat_id] => 3 [cat_name] => Drink [checkbox] => checked ) [3] => Array ( [cat_id] => 4 [cat_name] => Food [checkbox] => checked )
<br>
I then encoded it using:
echo json_encode($result);
Next, I fetched the data into a JavaScript variable with the following code:
result = Request.responseText;
var categories = JSON && JSON.parse(result) || $.parseJSON(result);
The challenge now is how to access the rows of data stored in the 'categories' variable. Upon verifying that the JSON encoding was successful by confirming that 'categories' is now of type [Object object]
, I am unsure of what steps to take next.