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);

?>

You didn't say what is the problem or what you don't know how to do it.

So, let me suggest you something, test your getdat.php in the browser and see what is the result.

this is a printscreen of what i get, not the actual data from the db

Just a guess, but I think you have to use "" instead of '' to assing the variables into the text.

Try like this: "<th>{$header}</th>\n" and "<th>{$value}</th>\n"

Thanks, it worked when i did it like this :"<th>".$header."</th>\n"
Now i want to show for every row a delete and edit button,is it possible to do it with ajax, so when i click delete button it automatically dissapears, or when i click edit i can edit it from there, Do ypu know any code or tutorial?

Sorry, I don't have any tutorials or code to land you in this case. I don't code much in PHP.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.