Good evening. I downloaded the graphics for the site, so, there the curve in the plane is given by the following line:

[['27-Mar-13',500], ['20-Jun-10', 30.45], ['25-Jul-10', 480.88], ['22-Aug-10', 1000.84], ['26-Sep-10', 654.13], ['24-Oct-10', 779.75], ['21-Nov-10', 803], ['21-Nov-10', 903], ['26-Dec-10', 908.56], ['23-Jan-10', 501.14], ['20-Feb-10', 1056.51], ['20-Mar-10', 1225.99], ['24-Apr-10', 1386.15]] 

This line indicates the date and payment, how can I make such a line when sampling from the database?

  • Do you want to get the results from the base and write them into a string with such punctuation or vice versa, parse the string into date-value values ​​in order to write values ​​to the base table? - void
  • Write a line with such punctuation - angers777
  • And what exactly you puzzled? Date + Sum, array, cycle, implode (if desired). Or do you want to get it right from the base? - xEdelweiss
  • I think this Json is somehow cleverly fictional coded - angers777
  • one
    First decipher the line "how can I make such a string when fetching from the database"? What data (and in what form) is on hand; in what form should they be after format conversion? What-where was going to write? - Bars

2 answers 2

I am writing blindly, there may be errors:

 function row_join($date, $price) { return "['$date', $price]"; } $sth = $dbh->prepare('select `date`, `price` from `table`'); $sth->execute(); $result = $sth->fetchAll(PDO::FETCH_FUNC, 'row_join'); $string = '['.implode(',', $result).']'; 
  • Aha)) Scha @ angers777 will fall into a stupor)) @klopp, risk being drawn into a long conversation on PDO;) - Deonis
  • I am generally familiar with OOP, so I will not fall. Sleep well, comrade Deonis;) - angers777
  • one
    OOP here and close did not stand. BTW, this is just an example - not the fact that it is better or more productive than manually assembling a string, or some other method. - user6550

Well, like this (I hope you can do it from the SELECT database).

 echo "["; //начало тела цикла - перебор значений, выбранных с базы echo "['" . $row['data'] . "'," . $row['digt'] . "],"; // конец тела цикла echo "]"; 
  • Thanks, but not very successful implementation. I actually can do it, but I would like to see how the professional will do it, but thanks for the answer anyway - angers777
  • four
    What difference does it make someone else? I have to learn with my head to think, this is a problem for solving on the knee ... - user6550