I have 2 mysql tables, one parent table (75 rows) and one child table (650+ rows) that has a foreign key connecting each child to a parent. I done numerous attempts to try to get them in this format but I keep failing:
// object literal holding data for option elements
var Select_List_Data = {
'choices': { // name of associated select box
// names match option values in controlling select box
parent_js: {
text: ['Scrolling Divs', 'Tooltips', 'Rotate Images', 'Scrollers', 'Banner Rotator'],
value: ['scroll', 'tooltips', 'rotate', 'scrollers', 'banner']
},
parent_php: {
text: ['Random Image', 'Form Class', 'Table Class', 'Order Form'],
value: ['random', 'form', 'table', 'order']
},
parent_tuts: {
// example without values
text: ['Iframes', 'PHP to JS', 'Object Literals', 'Initializing JS']
}
}
};
This is my code so far:
$program_makes = "";
$sql = "SELECT c.program_makes_id make_id, c.program_makes_model_name make, d.program_models_make, d.program_models_model model
FROM program_makes AS c
LEFT JOIN program_models AS d ON c.program_makes_id = d.program_models_make
ORDER BY c.program_makes_id ASC, d.program_models_make ASC;";
$stmt = $db->prepare($sql);
$result = $stmt->execute();
$stmt_result = $stmt->get_result();
$data = array();
if ($stmt_result->num_rows > 0) {
while ($row = $stmt_result->fetch_assoc()) {
$data[] = array("make"=>$row["make"], "model"=>$row["model"]);
$post_data = json_encode(array('max' => 46, 'data' => $data));
// $program_makes .= "<option value='".$row['program_models_model']."'>".$row['program_models_model']."</option>";
}
}
echo $post_data;
?>
<script>
jQuery.extend({
getValues: function(url) {
var result = null;
$.ajax({
url: url,
type: 'get',
dataType: 'json',
async: false,
success: function(data) {
result = JSON.stringify(data);
}
});
return result;
}
});
var testData = $.getValues("test.php");
</script>