For my new project i want the so modern approach of not needing to reload a page on every database request. :) I want the script to query the database and create a table wit
You may invert the logic, and do it on client side, using a library that does that automatically, like http://phery-php-ajax.net Instead of creating the table on the server side, send it as JSON to the browser, which is faster, and build your table:
Phery::instance()->set(array(
'load' => function(){
/* rest of mysql code */
$rows = array();
while($row = mysql_fetch_assoc($facebook)) { $rows[] = $row; }
return PheryResponse::factory()->json($rows);
})->process();
then in the client side inside $(function(){});
$(function(){
var $result_table = $('#result_table');
$result_table.phery('make', 'load');
$result_table.bind('phery:json', function(e, data){
var $this = $(this);
for (var i = 0; i < data.length; i++) {
$this.append($('<tr/>', {
'html': '<td>' + data[i].row_name + '</td>'
}));
}
});
$result_table.phery('remote');
});
Instead of
$output_string .= '<td>{$value}</td>';
try
$output_string .= "<td>{$value}</td>";
i.e. replace the single quotes with double quotes.
See the doc here, which says:
When a string is specified in double quotes ... variables are parsed within it.
and
variables ... will not be expanded when they occur in single quoted strings.
You should just use $value instead of {$value}. You don't need another foreach loop inside the while loop.
$output_string = '';
$output_string .= '<table border="1">';
while($row = mysql_fetch_assoc($facebook))
{
$output_string .= '<tr>';
$output_string .= '<td>'.$row['Your table column name here'].'</td>';
$output_string .= '</tr>';
}
$output_string .= '</table>';