1

I'm working on a project for school, I have to take data from a db (created on PhPMyAdmin) and create a graphic. I use PHP for get the data and Javascript to create the graphic, but I found and error and I can't get rid of it: when i lunch my html file the graphic structure appears, but it's empty. If I check Firefox console I get the error: ‘no element found’ and it's refered to php file.

PHP code:

<?php
require("conf.php");
$query="SELECT * FROM straniera";
$result=mysql_query($query);
$i=0;
$valori = array();
while($row=mysql_fetch_array($result)) {
    $valori[$i]=$row['2011'];
    $i++;
}
return $valori;
?>

Javascript code that lunch php:

var d = $.ajax({
                   type: "POST",
                       url: 'try.php'
              });
graphic(d);
1
  • 2
    Your code needs to echo something not return it. However you can't just echo an array like this and expect it to work in javascript Commented Jul 11, 2013 at 15:14

1 Answer 1

1

You should change 'return' to 'echo' in php code, and echo something wrapped as html.

<?php
require("conf.php");
$query="SELECT * FROM straniera";
$result=mysql_query($query);
$i=0;
$valori = "";
while($row=mysql_fetch_array($result)) {

    $valori.= "<li>".$row['2011'].</li>;
}
echo $valori;
?>

Ajax should be:

$.ajax({
            type:"GET",
            url:"try.php",
            success: function(data){
                    $("#somediv ul").html(data);
                }
            });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.