I have two tables A & B
TableA // (People)
UserID Name
10 Dan
20 Jane
30 Shelley
TableB // (Pics)
PicID UserID
100 10
200 10
300 20
I want to take everything from Table A and load it into an array and then add arrays for the images within the array but am unsure how to do this:
Currently for Table A I think:
$query = "select * from TableA";
$result = $mysqli->query($query) or die(mysqli_error($mysqli));
while ($row = $result->fetch_array()){
$array[] = $row;
// do another select here to get pics and add data to array multiDimensionally
}
echo json_encode($array);
Then I'm reading it like:
$.ajax({
url: apiURL,
dataType: 'json',
success: onLoadData
});
function onLoadData(data) {
// Create HTML for the images.
var html = '';
var i = 0, length = data.length, image;
for (; i < length; i++) {
image = data[i];
html += '<div class="holder">';
html += '<div class="name">' + image.Name + '</div>;
// do another loop here to show images for each person
html += '</div>';
}
Is this the best way to do it and if so, how would I add to the array and then read from it?