· 10 years ago · Sep 10, 2016, 11:46 AM
1CREATE TABLE IF NOT EXISTS `coffee` (
2 `id` int(11) NOT NULL AUTO_INCREMENT,
3 `name` varchar(255) DEFAULT NULL,
4 `type` varchar(255) DEFAULT NULL,
5 `price` double DEFAULT NULL,
6 `roast` varchar(255) DEFAULT NULL,
7 `country` varchar(255) DEFAULT NULL,
8 `image` varchar(255) DEFAULT NULL,
9 `review` text,
10 `ide` text,
11 PRIMARY KEY (`id`)
12) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;
13
14--
15-- Gegevens worden uitgevoerd voor tabel `coffee`
16--
17
18INSERT INTO `coffee` (`id`, `name`, `type`, `price`, `roast`, `country`, `image`, `review`) VALUES
19(1, 'Cafe au Lait', 'Classic', 2.25, 'Medium', 'France', 'Images/Coffee/Cafe-Au-Lait.jpg', 'A coffee beverage consisting strong or bold coffee (sometimes espresso) mixed with scalded milk in approximately a 1:1 ratio.'')'),
20(2, 'Caffe Americano', 'Espresso', 3.25, 'Medium', 'Italy', 'Images/coffee/caffe_americano.jpg', 'Similar in strength and taste to American-style brewed coffee, there are subtle differences achieved by pulling a fresh shot of espresso for the beverage base.'),
21(3, 'Peppermint White Chocolate Mocha', 'Espresso', 3.25, 'Medium', 'Italy', 'Images/coffee/white-chocolate-peppermint-mocha.jpg', 'Espresso with white chocolate and peppermint flavored syrups and steamed milk. Topped with sweetened whipped cream and dark chocolate curls.'),
22(4, 'Galao', 'Latte', 4.2, 'Light', 'Portugal', 'Images/Coffee/galao_kaffee_portugal.jpg', 'Galao is a hot drink from Portugal made of espresso and foamed milk');
23
24
25Contiene la base de datos de la tabla:
26//Get coffeeEntity objects from the database and return them in an array.
27 function GetCoffeeByType($type) {
28 require ('Credentials.php');
29 //Open connection and Select database.
30 mysql_connect($host, $user, $passwd) or die(mysql_error);
31 mysql_select_db($database);
32
33 $query = "SELECT * FROM coffee WHERE type LIKE '$type'";
34 $result = mysql_query($query) or die(mysql_error());
35 $coffeeArray = array();
36
37 //Get data from database.
38 while ($row = mysql_fetch_array($result)) {
39 $id = $row[0];
40 $name = $row[1];
41 $type = $row[2];
42 $price = $row[3];
43 $roast = $row[4];
44 $country = $row[5];
45 $image = $row[6];
46 $review = $row[7];
47$ide = $row[8];
48
49 //Create coffee objects and store them in an array.
50 $coffee = new CoffeeEntity($id, $name, $type, $price, $roast, $country, $image, $review);
51 array_push($coffeeArray, $coffee);
52 }
53 //Close connection and return result
54 mysql_close();
55 return $coffeeArray;
56 }
57
58
59Y aqui esta el php final que conecta:
60<?php
61$title = "Manage coffee objects";
62include './Controller/CoffeeController.php';
63$coffeeController = new CoffeeController();
64
65$content = $coffeeController->CreateOverviewTable();
66
67if(isset($_POST['types']))
68{
69 //Fill page with coffees of the selected type
70 $coffeeTables = $coffeeController->CreateCoffeeTables($_POST['types']);
71}
72else
73{
74 //Page is loaded for the first time, no type selected -> Fetch all types
75 $coffeeTables = $coffeeController->CreateCoffeeTables('%');
76}
77
78if(isset($_GET["delete"]))
79{
80 $coffeeController->DeleteCoffee($_GET["delete"]);
81}
82
83include './Template.php';
84?>
85
86
87
88Cualquier sugerencia es bien recibida. Lo que quiero es incluir un input y un type para buscar en cada columna de la tabla.