Forum - jschmidt-systemberatung.de

× php-RGraph and php-rgraph Joomla Content Plugin

Data from MySql Database using K2

  • Vlask
  • Visitor
  • Visitor
2 years 2 months ago #1231 by Vlask
Data from MySql Database using K2 was created by Vlask
Hello, thanks for great plugins. I have one issue, that i don't know how solve, since i know next to nothing about php or programming. I'm using onsite K2 modificiation which is using diffent type of mysql data. So i cannot use standard commands to get required data from myslql database. I want to fetch data for graphs from extra fields, which is K2 modification.

Friend of mine made for me mysql command to get required data from phmysqladmin, then i save them as csv and show using old flashchart plugin. Since flash is outdated, i wanted to use php-RGraph and skip step with manual saving to csv and rather use direct reading from database. Sadly i do not know how, because when i try replace code for sql query in your sample code at  www.jschmidt-systemberatung.de/index.php...2&Itemid=659&lang=en

with code needed to get data from K2 extra fields i get only this error 
*** php-rgraph - invalid/missing parameter:
  - no data found via sql="SELECT title, round(substr(extra_fields, ((locate('{"

I guess that issue here is using " for mysql command, because this is also used in many parts of code used for extracting data from k2 extra fields. 

Working code i'm using in phpmyslqadmin to get data for csv looks like this....

SELECT
title,
round(substr(extra_fields,
((locate('{"id":"29","value":"',extra_fields))+(char_length('{"id":"29","value":"'))),
((locate('"}',extra_fields,((locate('{"id":"29","value":"',extra_fields)+(char_length('{"id":"29","value":"'))))))-(locate('{"id":"29","value":"',extra_fields))-(char_length('{"id":"29","value":"')))
))
as final
FROM umhtg_k2_items where substr(extra_fields,
((locate('{"id":"29","value":"',extra_fields))+(char_length('{"id":"29","value":"'))),
((locate('"}',extra_fields,((locate('{"id":"29","value":"',extra_fields)+(char_length('{"id":"29","value":"'))))))-(locate('{"id":"29","value":"',extra_fields))-(char_length('{"id":"29","value":"')))
) >1
order by
cast(substr(extra_fields,
((locate('{"id":"29","value":"',extra_fields))+(char_length('{"id":"29","value":"'))),
((locate('"}',extra_fields,((locate('{"id":"29","value":"',extra_fields)+(char_length('{"id":"29","value":"'))))))-(locate('{"id":"29","value":"',extra_fields))-(char_length('{"id":"29","value":"')))) as decimal)  desc

Is there any way to make this work or should i stay with reading data from csv files?

Wanted to do it few years ago with flashchart and got reply that data are coded JSON, thats why sql code is so long. This is reply from one of K2 moderators...
www.joomlaworks.net/forum/k2-en/41456-k2-vs-flashchart

Please Log in or Create an account to join the conversation.

More
2 years 2 months ago #1234 by jochen
Replied by jochen on topic Data from MySql Database using K2
hi,

php-rgraph cannot proccess this kind of sql (one reason is that  rgraph uses as delimiter curly brackets ("{" "}") and cannot proccess sql containing these brackets).
You may use (code) a database interface, which creates as a result JSON-format  data using data parameter "url"

See an example on my site:
www.jschmidt-systemberatung.de/index.php...5&Itemid=659&lang=en

Please Log in or Create an account to join the conversation.

More
2 years 2 months ago - 7 months 1 week ago #1235 by jochen
Replied by jochen on topic Data from MySql Database using K2
hi,
you may try this:

Install php-RGraph (download-url: www.jschmidt-systemberatung.de/downloads/php-RGraph-V2.zip ) e.g. into
'/php-apps'

1. change all double-qotes(") in your sql into "qq"
2. create this code 'getJsonDatafromDB.php' in your 'templates/system' directory

<?php
defined('_JEXEC') or die('Restricted access');
$lib = JPATH_ROOT . "/php-apps/RGraph/lib/rgraph_chart.php";
require_once ($lib);
$db_config_file = $_SERVER["DOCUMENT_ROOT"] . "/configuration.php";
$sql="SELECT
title,
round(substr(extra_fields,
((locate('{qqidqq:qq29qq,qqvalueqq:qq',extra_fields))+(char_length('{qqidqq:qq29qq,qqvalueqq:qq'))),
((locate('qq}',extra_fields,((locate('{qqidqq:qq29qq,qqvalueqq:qq',extra_fields)+(char_length('{qqidqq:qq29qq,qqvalueqq:qq'))))))-(locate('{qqidqq:qq29qq,qqvalueqq:qq',extra_fields))-(char_length('{qqidqq:qq29qq,qqvalueqq:qq')))
))
as final
FROM umhtg_k2_items where substr(extra_fields,
((locate('{qqidqq:qq29qq,qqvalueqq:qq',extra_fields))+(char_length('{qqidqq:qq29qq,qqvalueqq:qq'))),
((locate('qq}',extra_fields,((locate('{qqidqq:qq29qq,qqvalueqq:qq',extra_fields)+(char_length('{qqidqq:qq29qq,qqvalueqq:qq'))))))-(locate('{qqidqq:qq29qq,qqvalueqq:qq',extra_fields))-(char_length('{qqidqq:qq29qq,qqvalueqq:qq')))
) >1
order by
cast(substr(extra_fields,
((locate('{qqidqq:qq29qq,qqvalueqq:qq',extra_fields))+(char_length('{qqidqq:qq29qq,qqvalueqq:qq'))),
((locate('qq}',extra_fields,((locate('{qqidqq:qq29qq,qqvalueqq:qq',extra_fields)+(char_length('{qqidqq:qq29qq,qqvalueqq:qq'))))))-(locate('{qqidqq:qq29qq,qqvalueqq:qq',extra_fields))-(char_length('{qqidqq:qq29qq,qqvalueqq:qq')))) as decimal)  desc";
$sql = str_replace('qq', '"', $sql);
$dbdata = rgraph_chart::getDataFromDB($db_config_file, $sql);
$data = array("labels"=>$dbdata[0], "data"=>$dbdata[1]);
echo json_encode($data);
?>



3. build rgraph plugin paramters like
{rgraph height="400" width="600" variantThreedOffsety="10" variantThreedOffsetx="15"data="url" url="http://your-host/index.php?option=com_content&tmpl=getJsonDatafromDB" type="Bar" tooltip="#label# <br>#val#" title="your title" marginBottom="105" truncate_label="20,.." variant="3d" tooltipsPositionStatic="0"}sample006{/rgraph}
Last edit: 7 months 1 week ago by jochen.
The following user(s) said Thank You: Vlask

Please Log in or Create an account to join the conversation.

  • Vlask
  • Visitor
  • Visitor
2 years 2 months ago #1245 by Vlask
Replied by Vlask on topic Data from MySql Database using K2
Thanks a lot, it works!!!!!
Still have some minor issues, but i guess it just needs some more documentation reading.

Now it looks like this and i'm very happy that it works at all

vgamuseum.info/index.php/charts/test-area

goal is to make it look like old flash version

vgamuseum.info/index.php/charts/fillrates

So i may have some few questions for you....

1) if i want more graphs i guess just copy getJsonDatafromDB.php and rename it to for example getJsonDatafromDB1.php and then edit mysql code in it and in another article just call new getJsonDatafromDB1.php file.....

2)can i use % of width and height in defining graph sizes? because in flashchart its working great, charts are dynamicaly changing size according to browser window and height according to number of records. I tried to change default width in backend plugin settings, but it won't allow me enter %, only numbers are accepted. Height in % would be great too. Should i use code in article, or its there a way how to set it in plugin backend?
Tried using 100% width in article code and it only shinked graph size....

3)any quick tip how to show numbers on the right side of graph bars? some numbers are really low compared to highest and bar sizes are too tiny to even click on them by mouse to see value :-)

4)how to make show whole text description of bars in chart? tried to change Default left margin to 50 in plugin backend, it helped a little bit, but increasing this number even higher has zero effect.

Please Log in or Create an account to join the conversation.

  • Vlask
  • Visitor
  • Visitor
2 years 2 months ago - 2 years 2 months ago #1246 by Vlask
Replied by Vlask on topic Data from MySql Database using K2
Edit: found how to fix number 4 - its defined by truncate_label="20,..".
And number 3) its done by labelsAbove="true"

No need to answer that....or anything at all if you dont have time... i will eventually find the solution....
Last edit: 2 years 2 months ago by Vlask.

Please Log in or Create an account to join the conversation.

More
2 years 2 months ago #1247 by jochen
Replied by jochen on topic Data from MySql Database using K2
hi,

glad to hear that my proposal works...

here some hints to your questions:
1. you may of course have any number of copies of db php-script (you call it via your its name in url-parameter)
2.you cannot use percent values for width or height (html5 'canvas' doesnot support this)
3.you found it: - its done by labelsAbove="true"
4.what do you mean with "text description of bars" (you mean tooltips)?

cannot access your flashchart sample ( vgamuseum.info/index.php/charts/fillrates ) - it kills  my browser (firefox)

Please Log in or Create an account to join the conversation.

Time to create page: 0.301 seconds
Powered by Kunena Forum
We use cookies

We use cookies on our website. Some of them are essential for the operation of the site, while others help us to improve this site and the user experience (tracking cookies). You can decide for yourself whether you want to allow cookies or not. Please note that if you reject them, you may not be able to use all the functionalities of the site.