0

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

?>
2
Contributors
5
Replies
25
Views
4 Years
Discussion Span
Last Post by AleMonteiro
0

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.

0

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

Attachments Untitled.png 10.64 KB
0

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"

0

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?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.