Menu

mssql query draw bar plot

florinS
2013-10-24
2013-10-24
  • florinS

    florinS - 2013-10-24

    Hello guys.
    I am trying to query a mssql database toi build a plot. The thing is that i need multiple bars for each hour. Raw code i mean this (where 100,200,300 are seconds):

    $data = array(array('hour 8', 100, 200, 300)));

    I am trying to achieve this with the following code:

    $query=mssql_query("SELECT ....");
    $cici = array();
    while( $agrow2 = mssql_fetch_array( $query ) ) {
    $cici[] = $agrow2['d'];
    }

    $prefix = '';
    $lista='';
    foreach ($cici as $valo)
    {
    $lista .= $prefix . '' . $valo . '';
    $prefix = ', ';
    }

    if i echo $lista i get something like this 100, 200, 300
    But if i try to add it like this:
    $data = array(array('hour 8', $lista)); it doesn't work. Other way of doing it i don't know. Can you please give me a hint on makeing this work. Thanks!

     
  • lbayuk

    lbayuk - 2013-10-24

    No, it isn't going to work that way because $lista is a string (which happens to contain a comma-separated list of numbers). It's like the difference between array(1, 2, 3) and array("1, 2, 3"). The first makes an array with 3 elements which are numbers, and the second makes an array with a single element which is a string.

    You need to show us more information to help. If you are plotting multiple points, and multiple bars per point, then you would have a 2-dimensional data set. But you are only taking 1 column ('d') from your data table. How does this become a 2-dimensional set of values with (row, column) indexes?

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.