So, i want to display data from a table in my db (Mysql), i click the buttonto get the data, it sends request via Ajax and Ajax calls getdata.php file. The table which is supposed to return the data returns in everyfield the written code like "$head" and "$value". I suppose it's the db connection isn't it?
Here is the connect.php
<?php
$db = mysql_connect("localhost", "root","");
mysql_select_db("agenda",$db) or die(mysql_error() . ": " . mysql_error() . "<br>");
?>
and this is the getdat.php
<?php
include('connect.php');
//Query of facebook database
$kontakte = mysql_query('SELECT * FROM kontakte')
or die(mysql_error());
//Output results
if(!$kontakte)
{
mysql_close();
echo json_encode('There was an error running the query: ' . mysql_error());
}
elseif(!mysql_num_rows($kontakte))
{
mysql_close();
echo json_encode('No results returned');
}
else
{
$header = false;
$output_string = '';
$output_string .= '<table border="1">\n';
while($row = mysql_fetch_assoc($kontakte))
{
if(!$header)
{
$output_string .= '<tr>\n';
foreach($row as $header => $value)
{
$output_string .= '<th>{$header}</th>\n';
}
$output_string .= '</tr>\n';
}
$output_string .= '<tr>\n';
foreach($row as $value)
{
$output_string .= '<th>{$value}</th>\n';
}
$output_string .= '</tr>\n';
}
$output_string .= '</table>\n';
}
mysql_close();
// This echo for jquery
echo json_encode($output_string);
?>