-1
var hbar = new RGraph.HBar('cvs', [100,700])

The above code is a JavasSript function which generates a bar graph 100 and 700 as parameters. The problem is MySql coloumn values. I need to pass through that function to get a complete graph of values that are been inserted.
database name :fosdb   Table name [vedordb]   coloumn name [name]

under name
jack
james
  are values Tried few code snippets but was unable to figure out how to detect those mysql coloumn values and fetch them to javascript variables using php.

Ex: say MySql coloumn 'Aname' has values inserted with 100, 300

I need first fetch them to PHP; repeat a loop depending on the length then assign each array to a JavaScript loop which assigns one more array then pass these array variables to the above JavaScript function so that I can see dynamic results every time.

Please help me out friends. Thanks in advance.

1
  • 1
    Please show your entire code, especially your current mysql/php code Commented Feb 22, 2014 at 8:28

1 Answer 1

1

Take a look on this example, its similar to like this:

//$database_data = array(100, 200);
$data_collector = array();

// Your Query here
$stmt = "select Aname from Table_Name";
$query = mysql_query($stmt);

while( $row = mysql_fetch_array($query) ) {
    $data_collector[] = $row['Aname'];
}

// Implode it
$collection = implode(", ", $data_collector);

PHP data Example : http://codepad.org/SRvxXjVK

Now pass $collection to JavaScript array like:

var Collection = [<?php echo $collection ?>];

// OR according to your code
var hbar = new RGraph.HBar('cvs', [<?php echo $collection ?>])

Hope this help you.

4
  • hii jogesh thanks for reply<br> i want to get mysql values to that variable $database_data i.e., don't want to enter manually those (100,200)and then assign those array variables to javascript.<br> i'm clear with rest of the part Commented Feb 22, 2014 at 8:35
  • @user2389346 how do i guess you database? you should show us your database query. Better is update your question and add your query. Commented Feb 22, 2014 at 8:44
  • i have updated my question jogesh please do look at it. thank you Commented Feb 22, 2014 at 13:40
  • thanks to jogesh_pi..now my code works i fell love with stackoverflow now...:) Commented Feb 23, 2014 at 8:10

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.