if your programming skills are limited, then you could use the below code to integrate google charts to your intranet or internet web site.
As i first step i usually visit the the google charts page and select a chart that matches my desired outcome. Lets say that we have a list of cd collections that we want to process and we need to know graphically how many we have already processed or not. For that i would choose a pie chart.
Mysql Part
Next we need to retrieve the necessary data from the database using the appropriate query.
mysql_queryIn my case i only need to have two columns, one that shows the cd collection visibility type (1=visible, 0= hidden, 3=other status), and the count of each type of visibility.
PHP Part
Next, the php part of the mysql connection:
mysql_select_db($database_localhost, $localhost);
$query_Recordset1 = "select count(*) as count,visible from cdcollection where type=1 and serial=1 group by visible";
$Recordset1 = mysql_query($query_Recordset1, $localhost) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
Then right below add the following script part, which basically transform the data array to json and then it uses it to create the chart.
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart1);
function drawChart1() {
var data = google.visualization.arrayToDataTable(<?php echo json_encode($data)?>);
var options = {
title: 'Collections',
hAxis: {title: 'Year', titleTextStyle: {color: 'red'}},
colors: ['#e0440e', '#e6693e', '#ec8f6e', '#f3b49f', '#f6c7b6']
};
var chart = new google.visualization.PieChart(document.getElementById('chart_div1'));
chart.draw(data, options);
</script>
I am explaining the red parts of the above code:
The json_encode($data) part transform the $data array to json. So in the mysql part if you used some other name for your dataset it should also be changed here.
The part right after “var options = { “ includes all the settings of the chart. This is where you specify the title, the colour style, the fonts etc. Depending on what you need to do adequate documentation exists on the net..
Finally, the last red part PieChart is where you tell the api what chart you need it to render. This could be modified to ColumnChart or Histogram or any other form the available options you can find in the google chart development page.
See below the dashboard i have create for my self using three different recordsets.
As mentioned earlier this week i changed my development machine to newer vmware win 7. During this, also upgraded from Wamp 2.2 to Wamp 2.5. Fortunatelly, i still keep both environments in parallel since various issues come up.
One of these issues is the one found today in php form (created with the dreamweaver CC wizard) that inserts some values into a mysql table. In my new dev machine i got these errors:
The old dev environment worked fine, the prod environment worked fine, the new dev threw errors.
I started by trying to find any compatibility issues in the PHP versions between Wamp Server 2.2 and 2.5, could not locate anything.
The solution came from the Stack Exchange (again). It appears that the php.ini on the new server came with the default value of
output_buffering = 4096
which should be changed to
output_buffering = on
which was the default on the old dev machine. To change the value in Wamp server just go to PHP menu and edit the php.ini to the mentioned value.
One alternative suggested by lots of people, which i did not try was to add
ob_start();
at the beggining of the script, which turns on the output buffering feature for the specific script.
For some time now i have this problem in one of the vm`s i use (win XP).When i edit a text document or start typing something, repeated keystrikes appear as if someone is pressing “c” on my keyboard.
In the beginning i thought that the cause of the problem was my XP machine, and the fact that i have been installing software from unsecure “origins”.. So i thought that a new vmware would be the solution to the problem. But NO! After backing up all my data, migrating it to a new windows 7 machine, and started using it in production use, guess..
It appears that this is a knowkn issue for vmware machines. I should have google it before doing all the work. This is how to get rid of it:
1. Power off the virtual machine.
2. Add a line, similar to this, at the end of your virtual machine’s configuration (.vmx) file
keyboard.typematicMinDelay = “2000000”
which equals to 2 seconds delay in the keyboard.
3. Start the vmware. You should be good to go.
Mike at “Single Founder” suggests the value can be changed to “500000”, since “2 seconds is a long time for computers”. I agree.
It turn`s out that there is an easy way to change the character set and collation of a single column in mysql. I usually have this issue since my provider has a swedish collation that is chosen by default when creating a column. I only realize after i get data in of course.. Here it is..
ALTER TABLE `packs`
MODIFY `packsname` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci;
To change the character set (and collation) for all columns in an existing table, use…
ALTER TABLE tbl_name CONVERT TO CHARACTER SET charset_name [COLLATE collation_name];
An alternative to this would be to convert the timestamp, during the query phase, which from what i read is not suggested, and of course did not work for me. Conversion in the php code allows you to use the timestamp with multiple forms in the same page e.g in meta and on footer notifying when this was published and by whom.
Today`s project was to generate an rss feed for the records in my web-project site using simple xml.
I new that most of the work had already been done, since i created the sitemap for my project. Check here.
So with a little search on the net i found some help. I am not going to write down all the steps that i ve taken to modify code written by others..but just to share some useful resources in case some novice php developer needs to do the same..
Initially i matched my existing code with the example written by Spotless Web Design. What a great and descriptive article…
Most of the word had already been done, but i needed to add some more quality stuff in the raw xml file like the atom link, so i got some more help from this guy.
Finally in order to validate the rss, i visited FeedValidator a couple of times.
That`s it for today … Next project is to link this RSS feed with an IFTTT rule to automatically post images to pintrest and twitter.. lets see how this goes.
I was trying to find an easy way to duplicate a table row in mysql, and it appears that mysql can handle that pretty easily. Just Use:
insert INTO `server`.`ad` (`adgrp`,`adname`,`ad`,`adlink`,`adtype`,`adprovider`,`visible`) SELECT `adgrp`,`adname`,`ad`,`adlink`,`adtype`,`adprovider`,`visible` FROM `server`.ad where idad=46;
to duplicate any row on any table, or use the CONCAT() function to add text to the newly created row. In my case i needed to set the name just to be “_copy” of the original one:
insert INTO `server`.`ad` (`adgrp`,`adname`,`ad`,`adlink`,`adtype`,`adprovider`,`visible`) SELECT `adgrp`,CONCAT(`adname`,"_COPY"),`ad`,`adlink`,`adtype`,`adprovider`,`visible` FROM `server`.ad where idad=46;
In the case above the idad column is of course the primary key and auto-increment, so it cannot be copied.
For my developing project i use Mysql and Dreamweaver set up with Wamp. I would say that i very familiar with databases and how to handle data etc..
Prerequisites to this project was that i could not modify either my php.ini or mysql.ini, since i am on a shared hosting plan.
One issue I had and could not fix though was that i got question-marks for special characters like quotes or Cyrillic or French characters using ascent. I did work on this many hours but with no luck. Today i finally have managed to solve it. Here is how:
Since all my databases already have data and are online, i created copies of them using the correct charset. So:
1. I Exported all the tables in my databases using mysqldump and recreated them using utf8 character set and utf8_unicode_ci table/column collation. This is essential to make sure all data are saved in the correct format
2. I made sure that all my pages had the following two meta tags in the head tag:
3. Finally, and that is what was missing all this time, is to make sure that all communication with the database is done through UTF. Apparently this does not happen automatically when you set the php encoding and the database collation/encoding. To do so, every time you query your database, you need to specify the communication encoding format.
mysql_select_db($database_localhost, $localhost);
$query_collections = sprintf("Select * from table WHERE packbrand=%s and serial='1' AND VISIBLE='1' order by collection asc", GetSQLValueString($colname_collections, "text"));
mysql_query("set names 'utf8'");
This last part basically fixed it.
What did not work for me:
Trying to figure our whether your text editor (like notepad++) is wrongly converting your query to a different encoding.
Pass the set names command in mysql workbench. While typing this i am just now realizing that this would not make any difference on way or an other, because it is the retrieval of the data in PHP that caused issues and not the displaying or the typing in..