Background
Okay, I have a page which displays simple information on rows from a mysql database. For example, the table has 7 columns, but only #'s 1, 3 & 4 are displayed on the page. On the right side of the row is a href link to open a modal window, and I am attempting to display all the rows, in a nicely formatted window with html/css/etc...
After spending about 4 hours in tutorials on this, the closest thing I have come up with is the code base below, which does the job of passing the "id" to the json script, (almost) properly pulls the information, puts it in a single object line, and passes it back into my html/php page to be read into the modal window.
I am politely asking for help to convert my codebase so that it transfers all objects individually instead of one gigantic line of php to echo into html (arse-backwards). I am rather new to JSON/AJAX/jquery, but can navigate and work with the html/css/php once I am able to figure this out.
My apologies if the code examples are a little muffled and poor in syntax, I have spent hours trying to get this work as it is supposed to.
PHP Page With The AJAX
$('.view_information').click(function(e) { // Button which will activate our modal
//On Clicking the function, dynamically load the data for the viewing
var data_id = $(this).data('id');
$.ajax({
url: 'view_agency_info.php',
type: 'POST',
data: {id: data_id},
dataType: 'json',
success: function(data){
$('.view_modal_content').html(data.html); // LOAD THE DATA INTO THIS DIV
//I want to be able to use...
//$('.placeholder_name')xxxx
//$('.placeholder_accountnumber')etc
},
error: function(jqXHR, textStatus, errorThrown){
$('.view_modal_content').html('');
alert('Error Loading Information');
}
});
As you can see from the php page, as of right now, the mysql is being pulled into an array, then inserted individually into a single HTML object, then being passed back into PHP to be outputted. How can I convert this code to output more than just one object?
JSON
<?php
$customer_id=$_SESSION['customer']['customer_id'];
$id = (int)$_POST['id'];
$query = "SELECT * FROM collections_list WHERE id={$id} && customer_id=$customer_id LIMIT 1"; //expecting one row
$result = mysql_query( $query );
//$message = mysql_fetch_assoc( $result ); //expecting just one row
$message=array();
while ($row = mysql_fetch_assoc($result)) {
$message[]=$row['agency_name'];
$message[]=$row['account_number'];
$message[]=$row['phone'];
}
$json = array();
$json['html'] = '<p><pre><code>id:'.$id.'.<br>Agency Name: '.$message[0].'<br>Account Number:'.$message[1]."<br>Phone:".$message[2].'</code></pre></p>'.'<br><br>test';
header('Content-Type: application/json');
echo json_encode( $json );
?>