Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP][MySQL] PHPLOT + SQL
rembasow1
post 18.11.2016, 12:13:32
Post #1





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 4.11.2016

Ostrzeżenie: (0%)
-----


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();
Go to the top of the page
+Quote Post
emstawicki
post 18.11.2016, 12:17:17
Post #2





Grupa: Zarejestrowani
Postów: 207
Pomógł: 40
Dołączył: 2.06.2016
Skąd: Olsztyn

Ostrzeżenie: (0%)
-----


Na szybko: nadpisujesz pętlą while za każdym razem (ile wierszy zwróci zapytanie) zmienną $example_data


--------------------
Jak w Olsztynie, to tylko w Revolver Rock Cafe .
Sprawdź postęp propagacji DNS
Go to the top of the page
+Quote Post
rad11
post 18.11.2016, 12:20:02
Post #3





Grupa: Zarejestrowani
Postów: 1 270
Pomógł: 184
Dołączył: 7.10.2012
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


Spróbuj:

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


Ten post edytował rad11 18.11.2016, 12:28:19
Go to the top of the page
+Quote Post
rembasow1
post 18.11.2016, 12:24:15
Post #4





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 4.11.2016

Ostrzeżenie: (0%)
-----


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`�
Go to the top of the page
+Quote Post
emstawicki
post 18.11.2016, 12:33:50
Post #5





Grupa: Zarejestrowani
Postów: 207
Pomógł: 40
Dołączył: 2.06.2016
Skąd: Olsztyn

Ostrzeżenie: (0%)
-----


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

Ten post edytował emstawicki 18.11.2016, 12:34:47


--------------------
Jak w Olsztynie, to tylko w Revolver Rock Cafe .
Sprawdź postęp propagacji DNS
Go to the top of the page
+Quote Post
rembasow1
post 18.11.2016, 12:57:43
Post #6





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 4.11.2016

Ostrzeżenie: (0%)
-----


Cytat(emstawicki @ 18.11.2016, 12:33:50 ) *
Nie zrozumiałeś o co chodzi.


I chyba nadal nie rozumiem ;/
Go to the top of the page
+Quote Post
emstawicki
post 18.11.2016, 13:00:38
Post #7





Grupa: Zarejestrowani
Postów: 207
Pomógł: 40
Dołączył: 2.06.2016
Skąd: Olsztyn

Ostrzeżenie: (0%)
-----


http://phpedia.pl/wiki/While

http://phpedia.pl/wiki/Array

Ostateczna próba.


--------------------
Jak w Olsztynie, to tylko w Revolver Rock Cafe .
Sprawdź postęp propagacji DNS
Go to the top of the page
+Quote Post
rembasow1
post 18.11.2016, 13:30:17
Post #8





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 4.11.2016

Ostrzeżenie: (0%)
-----


Nadal nic.
Mimo wszystko, dzięki za zaangażowanie.
Go to the top of the page
+Quote Post
emstawicki
post 18.11.2016, 13:40:49
Post #9





Grupa: Zarejestrowani
Postów: 207
Pomógł: 40
Dołączył: 2.06.2016
Skąd: Olsztyn

Ostrzeżenie: (0%)
-----


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)


--------------------
Jak w Olsztynie, to tylko w Revolver Rock Cafe .
Sprawdź postęp propagacji DNS
Go to the top of the page
+Quote Post
rembasow1
post 18.11.2016, 15:18:08
Post #10





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 4.11.2016

Ostrzeżenie: (0%)
-----


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
Go to the top of the page
+Quote Post
emstawicki
post 18.11.2016, 15:54:47
Post #11





Grupa: Zarejestrowani
Postów: 207
Pomógł: 40
Dołączył: 2.06.2016
Skąd: Olsztyn

Ostrzeżenie: (0%)
-----


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:


--------------------
Jak w Olsztynie, to tylko w Revolver Rock Cafe .
Sprawdź postęp propagacji DNS
Go to the top of the page
+Quote Post
rembasow1
post 18.11.2016, 16:36:14
Post #12





Grupa: Zarejestrowani
Postów: 7
Pomógł: 0
Dołączył: 4.11.2016

Ostrzeżenie: (0%)
-----


Dziękuje ślicznie.
Co do podstaw, to jutro wybieram się po książkę Helion'a o PHP, także obiecuję poprawę smile.gif
Go to the top of the page
+Quote Post
viking
post 18.11.2016, 16:50:06
Post #13





Grupa: Zarejestrowani
Postów: 6 365
Pomógł: 1114
Dołączył: 30.08.2006

Ostrzeżenie: (0%)
-----


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.


--------------------
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 23.04.2024 - 20:35