DB and PHP problem
FusionCharts Forum
Home       Members    Calendar    Who's On
Welcome Guest ( Login | Register )
        



DB and PHP problem Expand / Collapse
Author
Message
Posted 3/8/2008 7:02:23 AM
Junior Member

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member

Group: Forum Members
Last Login: 4/17/2008 7:19:40 AM
Posts: 12, Visits: 23
Hello,

I`ve got following table in mysql 5:

-- phpMyAdmin SQL Dump
-- version 2.7.0-pl2
-- http://www.phpmyadmin.net
--
-- Host: $hostdb
-- Server version: 5.0.32
-- PHP version: 4.3.10-16
--
-- DB: `$namedb`
--
-- --------------------------------------------------------
--
-- Table structure for  `EURUSD10MIN`
--
CREATE TABLE `EURUSD10MIN` (
  `id` mediumint(9) NOT NULL auto_increment,
  `timestamp` varchar(30) NOT NULL default '',
  `price` double(5,4) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=99 DEFAULT CHARSET=latin1 AUTO_INCREMENT=99 ;
--
-- Dumping data for table `EURUSD10MIN`
--
INSERT INTO `EURUSD10MIN` VALUES (85, 'Mar 07 2008 01:01:44', 1.5383);
INSERT INTO `EURUSD10MIN` VALUES (84, 'Mar 07 2008 00:01:43', 1.5383);
INSERT INTO `EURUSD10MIN` VALUES (82, 'Mar 06 2008 22:01:43', 1.5387);
INSERT INTO `EURUSD10MIN` VALUES (81, 'Mar 06 2008 21:01:43', 1.5380);
INSERT INTO `EURUSD10MIN` VALUES (80, 'Mar 06 2008 20:01:42', 1.5366);
INSERT INTO `EURUSD10MIN` VALUES (79, 'Mar 06 2008 19:01:43', 1.5376);
INSERT INTO `EURUSD10MIN` VALUES (78, 'Mar 06 2008 18:01:44', 1.5371);
INSERT INTO `EURUSD10MIN` VALUES (77, 'Mar 06 2008 17:02:37', 1.5356);

and this is your table (dump.sql from   FusionChartsFree\Code\PHP\DB\  ):

# MySQL dump
#
#--------------------------------------------------------
# Program Version 2.0.46
CREATE DATABASE IF NOT EXISTS `factorydb`;
USE `factorydb`;
#
# Table structure for table 'Factory_Master'
#
DROP TABLE IF EXISTS `Factory_Master`;
CREATE TABLE `Factory_Master` (
  `FactoryId` INTEGER NOT NULL AUTO_INCREMENT,
  `FactoryName` VARCHAR(50),
  INDEX (`FactoryName`),
  PRIMARY KEY (`FactoryId`)
) TYPE=MyISAM;
#
# Dumping data for table 'Factory_Master'
#
INSERT INTO `Factory_Master` VALUES (1, 'Factory 1');
INSERT INTO `Factory_Master` VALUES (2, 'Factory 2');
INSERT INTO `Factory_Master` VALUES (3, 'Factory 3');
# 3 records
#
# Table structure for table 'Factory_Output'
#
DROP TABLE IF EXISTS `Factory_Output`;
CREATE TABLE `Factory_Output` (
  `FactoryID` INTEGER DEFAULT 0,
  `DatePro` DATETIME DEFAULT 'Now()',
  `Quantity` DOUBLE NULL,
  INDEX (`FactoryID`)
) TYPE=MyISAM;
#
# Dumping data for table 'Factory_Output'
#
INSERT INTO `Factory_Output` VALUES (1, '2003-01-01 17:53:26', 21);
INSERT INTO `Factory_Output` VALUES (1, '2003-01-02 17:54:13', 23);
INSERT INTO `Factory_Output` VALUES (1, '2003-01-03 17:54:14', 22);
INSERT INTO `Factory_Output` VALUES (1, '2003-01-04 17:54:21', 24);
INSERT INTO `Factory_Output` VALUES (1, '2003-01-05 17:54:45', 32);
INSERT INTO `Factory_Output` VALUES (1, '2003-01-06 17:54:53', 21);
INSERT INTO `Factory_Output` VALUES (1, '2003-01-07 17:54:58', 34);
INSERT INTO `Factory_Output` VALUES (1, '2003-01-08 17:55:04', 32);
INSERT INTO `Factory_Output` VALUES (1, '2003-01-09 17:55:15', 32);
INSERT INTO `Factory_Output` VALUES (1, '2003-01-10 17:55:20', 23);
INSERT INTO `Factory_Output` VALUES (1, '2003-01-11 17:55:26', 23);
INSERT INTO `Factory_Output` VALUES (1, '2003-01-12 17:55:35', 32);
INSERT INTO `Factory_Output` VALUES (1, '2003-01-13 17:55:40', 53);
INSERT INTO `Factory_Output` VALUES (1, '2003-01-14 17:55:44', 23);
INSERT INTO `Factory_Output` VALUES (1, '2003-01-15 17:55:51', 26);
INSERT INTO `Factory_Output` VALUES (1, '2003-01-16 17:55:58', 43);
INSERT INTO `Factory_Output` VALUES (1, '2003-01-17 17:56:04', 16);
INSERT INTO `Factory_Output` VALUES (1, '2003-01-18 17:56:09', 45);
INSERT INTO `Factory_Output` VALUES (1, '2003-01-19 17:56:15', 65);
INSERT INTO `Factory_Output` VALUES (1, '2003-01-20 17:56:22', 54);
INSERT INTO `Factory_Output` VALUES (2, '2003-01-01 17:53:26', 121);
INSERT INTO `Factory_Output` VALUES (2, '2003-01-02 17:54:13', 123);
INSERT INTO `Factory_Output` VALUES (2, '2003-01-03 17:54:14', 122);
INSERT INTO `Factory_Output` VALUES (2, '2003-01-04 17:54:21', 124);
INSERT INTO `Factory_Output` VALUES (2, '2003-01-05 17:54:45', 132);
INSERT INTO `Factory_Output` VALUES (2, '2003-01-06 17:54:53', 121);
INSERT INTO `Factory_Output` VALUES (2, '2003-01-07 17:54:58', 134);
INSERT INTO `Factory_Output` VALUES (2, '2003-01-08 17:55:04', 132);
INSERT INTO `Factory_Output` VALUES (2, '2003-01-09 17:55:15', 132);
INSERT INTO `Factory_Output` VALUES (2, '2003-01-10 17:55:20', 123);
INSERT INTO `Factory_Output` VALUES (2, '2003-01-11 17:55:26', 123);
INSERT INTO `Factory_Output` VALUES (2, '2003-01-12 17:55:35', 132);
INSERT INTO `Factory_Output` VALUES (2, '2003-01-13 17:55:40', 153);
INSERT INTO `Factory_Output` VALUES (2, '2003-01-14 17:55:44', 123);
INSERT INTO `Factory_Output` VALUES (2, '2003-01-15 17:55:51', 126);
INSERT INTO `Factory_Output` VALUES (2, '2003-01-16 17:55:58', 143);
INSERT INTO `Factory_Output` VALUES (2, '2003-01-17 17:56:04', 116);
INSERT INTO `Factory_Output` VALUES (2, '2003-01-18 17:56:09', 145);
INSERT INTO `Factory_Output` VALUES (2, '2003-01-19 17:56:15', 165);
INSERT INTO `Factory_Output` VALUES (2, '2003-01-20 17:56:22', 154);
INSERT INTO `Factory_Output` VALUES (3, '2003-01-01 17:53:26', 54);
INSERT INTO `Factory_Output` VALUES (3, '2003-01-02 17:54:13', 56);
INSERT INTO `Factory_Output` VALUES (3, '2003-01-03 17:54:14', 89);
INSERT INTO `Factory_Output` VALUES (3, '2003-01-04 17:54:21', 56);
INSERT INTO `Factory_Output` VALUES (3, '2003-01-05 17:54:45', 98);
INSERT INTO `Factory_Output` VALUES (3, '2003-01-06 17:54:53', 76);
INSERT INTO `Factory_Output` VALUES (3, '2003-01-07 17:54:58', 65);
INSERT INTO `Factory_Output` VALUES (3, '2003-01-08 17:55:04', 45);
INSERT INTO `Factory_Output` VALUES (3, '2003-01-09 17:55:15', 75);
INSERT INTO `Factory_Output` VALUES (3, '2003-01-10 17:55:20', 54);
INSERT INTO `Factory_Output` VALUES (3, '2003-01-11 17:55:26', 75);
INSERT INTO `Factory_Output` VALUES (3, '2003-01-12 17:55:35', 76);
INSERT INTO `Factory_Output` VALUES (3, '2003-01-13 17:55:40', 34);
INSERT INTO `Factory_Output` VALUES (3, '2003-01-14 17:55:44', 97);
INSERT INTO `Factory_Output` VALUES (3, '2003-01-15 17:55:51', 55);
INSERT INTO `Factory_Output` VALUES (3, '2003-01-16 17:55:58', 43);
INSERT INTO `Factory_Output` VALUES (3, '2003-01-17 17:56:04', 16);
INSERT INTO `Factory_Output` VALUES (3, '2003-01-18 17:56:09', 35);
INSERT INTO `Factory_Output` VALUES (3, '2003-01-19 17:56:15', 78);
INSERT INTO `Factory_Output` VALUES (3, '2003-01-20 17:56:22', 75);
# 60 records

______________________________________________

this is my BasicDBExample.php for my EURUSD10MIN.sql:

<?php

//We've included ../Includes/FusionCharts.php and ../Includes/DBConn.php, which contains
//functions to help us easily embed the charts and connect to a database.

//i changing ../Includes/FusionCharts.php for only FusionCharts.php because FusionCharts.php  (DBConn.php and FusionCharts.js too) exist in the same folder where exist my BasicDBExample.php

include("FusionCharts.php");
include("DBConn.php");
?>


<HTML>
<HEAD>
 <TITLE>
 FusionCharts Free - Database Example
 </TITLE>
 <?php

 //You need to include the following JS file, if you intend to embed the chart using JavaScript.
 //Embedding using JavaScripts avoids the "Click to Activate..." issue in Internet Explorer
 //When you make your own charts, make sure that the path to this JS file is correct. Else, you would get JavaScript errors.

 ?>


 <SCRIPT LANGUAGE="Javascript" SRC="FusionCharts.js"></SCRIPT>


 <style type="text/css">
 <!--
 body {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 12px;
 }
 .text{
  font-family: Arial, Helvetica, sans-serif;
  font-size: 12px;
 }
 -->
 </style>


</HEAD>
<BODY>


<CENTER>
<h2><a href="http://www.fusioncharts.com" target="_blank">FusionCharts Free</a> -Database and Drill-Down Example</h2>


<?php
 //In this example, we show how to connect FusionCharts to a database.
 //For the sake of ease, we've used an MySQL databases containing two
 //tables.


 // Connect to the DB
 $link = connectToDB();

 //$strXML will be used to store the entire XML document generated
 //Generate the graph element
 $strXML = "<graph caption='Monthly Sales' animation="0" showAreaBorder='0' areaAlpha='90' SUBCAPTION='1000' YAXISNAME='qqqqqqqq' XAXISNAME='wwwwwwwwww'
subcaption='year 2006' xAxisName='Month' showNames='0' bgColor='ffffff' yAxisMaxValue='450' yAxisMinValue='300'
yAxisName='Sales' numberPrefix='$' decimalPrecision='2'>";


 // Fetch all factory records
 $strQuery = "select * from EURUSD10MIN";
 $result = mysql_query($strQuery) or die(mysql_error());

 //Iterate through each factory
 if ($result) {
  while($ors = mysql_fetch_array($result)) {
   //Now create a second query to get details for this factory
   $strQuery = "select sum(price) as TotOutput from EURUSD10MIN where id=" . $ors['id'];
   $result2 = mysql_query($strQuery) or die(mysql_error());
   $ors2 = mysql_fetch_array($result2);

   //Generate <set name='..' value='..' />
//I replace FactoryName and TotOutput


   $strXML .= "<set name='" . $ors['timestamp'] . "' value='" . $ors2['price'] . "'  color='000077'/>";

   //free the resultset
   mysql_free_result($result2);
  }
 }
 mysql_close($link);

 //Finally, close <graph> element
 $strXML .= "</graph>";

 //Create the chart - Pie 3D Chart with data from $strXML
i changing name of chart for short

 echo renderChart("x.swf", "", $strXML, "FactorySum", 650, 450, false, false);
?>
<BR><BR>
<a href='../NoChart.html' target="_blank">Unable to see the chart above?</a>
<H5 ><a href='../default.htm'>&laquo; Back to list of examples</a></h5>
</CENTER>
</BODY>
</HTML>

this is my DBConn.php:

<?php
// In this page, we open the connection to the Database
// In this page, we open the connection to the Database
// Our MySQL database (blueprintdb) for the Blueprint Application
// Function to connect to the DB
function connectToDB() {
    // These four parameters must be changed dependent on your MySQL settings
    $hostdb = 'xxx';   // MySQl host
    $userdb = 'xxx';    // MySQL username
    $passdb = 'xxxx';    // MySQL password
    $namedb = 'xxx'; // MySQL database name
    //$link = mysql_connect ("$hostdb", "$userdb", "$passdb");
 $link = mysql_connect ();
    if (!$link) {
        // we should have connected, but if any of the above parameters
        // are incorrect or we can't access the DB for some reason,
        // then we will stop execution here
        die('Could not connect: ' . mysql_error());
    }
    $db_selected = mysql_select_db($namedb);
    if (!$db_selected) {
        die ('Can\'t use database : ' . mysql_error());
    }
    return $link;
}
?>


and I don`t understand, I see No database selected

 elementary question, please tell me, how i should modify BasicDBExample.php  for my EURUSD10MIN table? I see in dump.sql two tables - Factory_Master and Factory_Output and (i dont know why) i can`t upload it to my MySQL db, I have only 1 simple table for simple linear chart (Area 2D chart), with id (for sort), timestamp (for x axis) and price (for y axis)

Post #5004
Posted 3/12/2008 9:17:31 AM
Junior Member

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member

Group: Forum Members
Last Login: 4/17/2008 7:19:40 AM
Posts: 12, Visits: 23
i think dbconn.php is good, but i dont understand what is FactoryName and TotOutput
Post #5031
« Prev Topic | Next Topic »


Permissions Expand / Collapse

All times are GMT -7:00, Time now is 7:40am


Execution: 0.156.