Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
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.

share|improve this question
1  
Please show your entire code, especially your current mysql/php code –  Axel Amthor Feb 22 '14 at 8:28

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
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 –  user2389346 Feb 22 '14 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. –  jogesh_pi Feb 22 '14 at 8:44
    
i have updated my question jogesh please do look at it. thank you –  user2389346 Feb 22 '14 at 13:40
    
@user2389346 i have updated the answer. –  jogesh_pi Feb 22 '14 at 16:41
    
thanks to jogesh_pi..now my code works i fell love with stackoverflow now...:) –  user2389346 Feb 23 '14 at 8:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.