Jump to content

Hey guys, who could test my skills ? :)


jankidudel

Recommended Posts

CREATE TABLE  `assignments`.`products` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR( 250 ) NOT NULL ,
`cost` DECIMAL( 10, 2 ) NOT NULL
) ENGINE = INNODB;


CREATE TABLE  `assignments`.`transactions` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`order_id` INT NOT NULL ,
`income` DECIMAL( 10, 2 ) NOT NULL ,
`cost` DECIMAL( 10, 2 ) NOT NULL ,
`data` DATE NOT NULL
) ENGINE = INNODB;

CREATE TABLE  `assignments`.`orders` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`client_id` INT NOT NULL ,
`product_id` INT NOT NULL ,
`data` DATE NOT NULL
) ENGINE = INNODB;

CREATE TABLE  `assignments`.`clients` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` INT( 250 ) NOT NULL ,
`lastname` INT( 250 ) NOT NULL
) ENGINE = INNODB;



<?php

class Myclass {

protected $db;

public function __construct()
{
	$this->db = new PDO("mysql:host=localhost;dbname=zadania", "root", "");
	//mysql_connect("localhost" , "root", "");
	//mysql_select_db("zadania");

}

public function getIncomeStatistics($month=1) {

	$query = "SELECT DAYOFMONTH(data) AS day, SUM(income) AS income, SUM(cost) AS cost 
		FROM transactions GROUP BY day";

		$results = $this->db->query($query);
		$results = $results->fetchAll();


		foreach($results as $result)
		{
			$item['day'] = $result['day'];
			$item['profit'] = $result['income'] - $result['cost'];
			$return[] = $item;
		}

	return $return;
}

public function getOrdersStatistics($month=1){

	$query = "SELECT products.name AS product, COUNT(orders.product_id) AS orders_num
		FROM products, orders WHERE products.id = orders.product_id GROUP BY products.id";



		$results = $this->db->query($query);
		$results = $results->fetchAll();

		foreach($results as $result)
		{
			$item['produkt'] = $result['produkt'];
			$item['liczba_zamowien'] = $result['liczba_zamowien'];
			$return[] = $item;
		}

	return $return;

}

public function getTopClients(){
	$query = "SELECT clients.name AS client, COUNT(orders.client_id) AS orders_num ,
		SUM(transactions.income) - SUM(transactions.cost) AS income FROM clients, orders, transactions
		WHERE clients.id = orders.client_id AND orders.id = transactions.order_id
		GROUP BY clients.id ORDER BY income DESC";

	$results = $this->db->query($query);

	$results = $results->fetchAll();
	foreach($results as $result)
	{
		$client['client'] = $result['client'];
		$client['orders_num'] = $result['orders_num'];
		$return[] = $client;
	}
	return $return;
}
}




?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.