Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP][MySQL] PHPLOT + SQL
Forum PHP.pl > Forum > Przedszkole
rembasow1
Witam, chciałbym stworzyć wykres na podstawie danych z tabeli z bazy MySQL. Problem polega na tym ze wykres jest pusty i nie uzupelnia sie danymi z tabeli. Błędy są zapewne w linijce 21-22 jednak nie wiem jak sobie z nimi poradzić. Bardzo proszę o pomoc i z góry dziękuję smile.gif

  1. <?php
  2. //Include the code
  3. require_once 'phplot.php';
  4.  
  5. mysql_connect("localhost", "root", "pass");
  6. //Define the object
  7. $query = mysql_query("SELECT ID, X1, X2, X3, X4, X5 FROM pomiary");
  8.  
  9.  
  10. $plot = new PHPlot(1000,750);
  11.  
  12. //Set titles
  13. $plot->SetTitle("A 3-Line Plot\nMade with PHPlot");
  14. $plot->SetXTitle('X Data');
  15. $plot->SetYTitle('Y Data');
  16.  
  17. WHILE($row = mysql_fetch_assoc($query))
  18. {
  19. //Define some data$row['']
  20. $example_data = array(
  21. array($row['ID'],$row['x1'],$row['x2'],$row['x3'],$row['x4'],$row['x5']),
  22.  
  23. );
  24. }
  25. $plot->SetDataValues($example_data);
  26.  
  27. //Turn off X axis ticks and labels because they get in the way:
  28. $plot->SetXTickLabelPos('none');
  29. $plot->SetXTickPos('none');
  30.  
  31. //Draw it
  32. $plot->DrawGraph();
emstawicki
Na szybko: nadpisujesz pętlą while za każdym razem (ile wierszy zwróci zapytanie) zmienną $example_data
rad11
Spróbuj:

  1. $example_data[] = array($row['ID'],$row['x1'],$row['x2'],$row['x3'],$row['x4'],$row['x5']);
rembasow1
Cytat(emstawicki @ 18.11.2016, 12:17:17 ) *
Na szybko: nadpisujesz pętlą while za każdym razem (ile wierszy zwróci zapytanie) zmienną $example_data


Problem w tym ze wiersze będą dodawane na bierząco (co godzine)




Cytat(rad11 @ 18.11.2016, 12:20:02 ) *
Spróbuj:

  1. $example_data[] = array(
  2. array($row['ID'],$row['x1'],$row['x2'],$row['x3'],$row['x4'],$row['x5']),
  3.  
  4. );



krzaki wyskakują :

Warning: explode() expects parameter 2 to be string, array given in /z4/phplot.php on line 1789

Warning: Invalid argument supplied for foreach() in /z4/phplot.php on line 1789

Warning: explode() expects parameter 2 to be string, array given in /z4/phplot.php on line 1789

Warning: Invalid argument supplied for foreach() in /z4/phplot.php on line 1789

Warning: explode() expects parameter 2 to be string, array given in /z4/phplot.php on line 1789

Warning: Invalid argument supplied for foreach() in /z4/phplot.php on line 1789

Warning: explode() expects parameter 2 to be string, array given in /z4/phplot.php on line 1789

Warning: Invalid argument supplied for foreach() in /z4/phplot.php on line 1789

Warning: explode() expects parameter 2 to be string, array given in /z4/phplot.php on line 1789

Warning: Invalid argument supplied for foreach() in /z4/phplot.php on line 1789

Warning: explode() expects parameter 2 to be string, array given in /z4/phplot.php on line 1789

Warning: Invalid argument supplied for foreach() in /z4/phplot.php on line 1789

Warning: Cannot modify header information - headers already sent by (output started at /z4/phplot.php:1789) in /z4/phplot.php on line 2288

Warning: Cannot modify header information - headers already sent by (output started at /z4/phplot.php:1789) in /z4/phplot.php on line 2289

Warning: Cannot modify header information - headers already sent by (output started at /z4/phplot.php:1789) in /z4/phplot.php on line 2290

Warning: Cannot modify header information - headers already sent by (output started at /z4/phplot.php:1789) in /z4/phplot.php on line 2291

Warning: Cannot modify header information - headers already sent by (output started at /z4/phplot.php:1789) in /z4/phplot.php on line 2311
�PNG  IHDR��@��� PLTE�������g��IDATx���A��6Fa�07]9�|�C:{s�!G�Q+r�7�� ���M� ��gJ�e�`)ffff��y����Ա������]zUm�Y�g�2OK��q{����R��C��9��r[��N��ڎ޹�mЧ���\�8ק�VȨ_��x^��>��ɻ�[����K���3��ב�����������{�}|�iK[�:�1��_�/��{gffff��:����������2�mz돱ۥ���>��en˼���{���0?GD�}�w+��oS�{�mj�m}���7G��u�������ӝ��m�z��V�i?���ů��Q��>�;�6���m�_�u\׷�������0�>�Q/Hz�����N����\W�~�ߖ� �/�u�����>m���֟k���Χ���������G}�׶���_���D/�q���{��/P���tDғtDғtDғtDғtDғtDғtDғtDғtDғtDғtDғtDғtDғtDғtDғtDғtDғtDғtD�n��߰�3�^������x�SG}�^�z�IO�IO�IO�IO�IO�IO�IO�IO�IO�IO�IO�IO�IO�IO�IO�IO�IO�IO�=�g.�ʥp�}&����J~��0��9u����"��$��$��$��$��$��$��$��$��$��$��$��$��$��$��$��$��$��$�S�F����Q����k%�j����"��$��$��$��$��$��$��$��$��$��$��$��$��$��$��$��$��$��$�#�q��%jOdzm��k%�j;?� �QӋtHғtDғtDғtDғtDғtDғtDғtDғtDғtDғtDғtDғtDғtDғtDғtDғtDғtDғtD.V:Z��?��[��|�Zɯ�\�y��鐤'鈤'鈤O��xܞ��;�r�����tD�s�~��#����� �T?���Ho�+|�>���U�HO@�wnD:��L��޹���9�g��{���x0=IG$=IG$=IGt�����sD:�Y0|��/sI:"�I:"��J/G�p��>�I��/���I�#'qS���#���#���#���#���#���#���#���#���#���#���#���#���#���#���#���#���#���#�>:q��ٍ���[��|�2ѯ�~<���:�^�C���#���#���#���#���#���#���#���#���#���#���#���#���#���#���#���#���#���#r:��D-xbg_����k%�j{�� >����"��$��$��$��$��$��$��$��$��$��$��$��$��$��$��$��$��$��$�S�F����~�3��_+�U���e��z�ҋtHғtDғtDғtDғtDғtDғtDғtDғtDғtDғtDғtDғtDғtDғtDғtDғtDғtDғtD��;O��z�ɼ�V��6G}t�ҋtHғtDғtDғtDғtDғtDғtDғtDғtDғtDғtDғtDғtDғtDғtDғtDғtDғtDғtD�n}���^�����t����u>���R�ޏ��2]$�t�����^��w��MK��������^յ�z�傣��c�G���>����m���x33�/����+�DIEND�B`�
emstawicki
Cytat
Problem w tym ze wiersze będą dodawane na bierząco (co godzine)

Nie zrozumiałeś o co chodzi.

Level hard:
$row = mysql_fetch_assoc($query) to zbiór jabłek.
w pętli dla każdego elementu ze zbioru robisz coś takiego:
$worek = $row;
Po pętli worek nie będzie zbiorem jabłek tylko jednym jabłkiem.

Co do kodu rad11 nie zwrócił uwagi jakie parametry (w dokumentacji) przyjmuje $plot->SetDataValues http://www.phplot.com/phplotdocs/SetDataValues.html + http://www.phplot.com/phplotdocs/SetDataType.html
rembasow1
Cytat(emstawicki @ 18.11.2016, 12:33:50 ) *
Nie zrozumiałeś o co chodzi.


I chyba nadal nie rozumiem ;/
emstawicki
http://phpedia.pl/wiki/While

http://phpedia.pl/wiki/Array

Ostateczna próba.
rembasow1
Nadal nic.
Mimo wszystko, dzięki za zaangażowanie.
emstawicki
Ja rozumiem, że ktoś chce coś zrobić bierze gotowca / przykład i próbuje go przerobić pod siebie. Ale podstawy (nie chodzi tutaj o nawet język) programowania i logiki trzeba mieć.

Zapomnijmy o tym skrypcie. Powiedz jakie masz dane i jaki wykres chcesz uzyskać za pomocą PHPlot? (może być nawet szkic w paincie)
rembasow1
No więc mam 5 punktów pomiarowych w tabeli bazy danych do której co jakiś czas dokładam formularzem nowe wartosci. Chciałbym stworzyć wykres wartosci pomiarow od id wprowadzanych pomiarów.

ID X1 X2 X3 X4 X5
1 5 3 2 7 1
2 3 2 7 1 5
3 2 7 1 5 3
emstawicki
Kod
ID X1 X2 X3 X4 X5
1 5 3 2 7 1
2 3 2 7 1 5
3 2 7 1 5 3

oraz:
  1. <?php
  2. //Include the code
  3. require_once 'phplot.php';
  4.  
  5. //Define the object
  6. $plot = new PHPlot(800,600);
  7.  
  8. //Set titles
  9. $plot->SetTitle("A 3-Line Plot\nMade with PHPlot");
  10. $plot->SetXTitle('ID');
  11. $plot->SetYTitle('Values');
  12.  
  13. mysql_connect("localhost", "root", "");
  14. $query = mysql_query("SELECT ID, X1, X2, X3, X4, X5 FROM pomiary");
  15.  
  16. $data = array();
  17.  
  18. while ($row = mysql_fetch_assoc($query)) {
  19. $data[] = $row;
  20. }
  21.  
  22. $plot->SetDataValues($data);
  23.  
  24. //Turn off X axis ticks and labels because they get in the way:
  25. $plot->SetXTickLabelPos('none');
  26. $plot->SetXTickPos('none');
  27.  
  28. //Draw it
  29. $plot->DrawGraph();

daje wynik:
rembasow1
Dziękuje ślicznie.
Co do podstaw, to jutro wybieram się po książkę Helion'a o PHP, także obiecuję poprawę smile.gif
viking
Książka już pewnie jest dawno przestarzała. Zwłaszcza że zaraz PHP 7.1 będzie wydane. Ucz się raczej z sieci i dokumentację czytaj.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.