I made a web page in php. But I want to add some things like input and type in each column to search in each table the corresponding field The corresponding table in mysql
CREATE TABLE IF NOT EXISTS 'coffee' (
'id' int(11) NOT NULL AUTO_INCREMENT,
'name' varchar(255) DEFAULT NULL,
'type' varchar(255) DEFAULT NULL,
'price' double DEFAULT NULL,
'roast' varchar(255) DEFAULT NULL,
'country' varchar(255) DEFAULT NULL,
'image' varchar(255) DEFAULT NULL,
'review' text,
'ide' text,
PRIMARY KEY ('id')
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;
--
-- Gegevens worden uitgevoerd voor tabel 'coffee'
--
INSERT INTO 'coffee' ('id', 'name', 'type', 'price', 'roast', 'country', 'image', 'review') VALUES
(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.'')'),
(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.'),
(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.'),
(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');
Contains the database of the table:
//Get coffeeEntity objects from the database and return them in an array.
function GetCoffeeByType($type) {
require ('Credentials.php');
//Open connection and Select database.
mysql_connect($host, $user, $passwd) or die(mysql_error);
mysql_select_db($database);
$query = "SELECT * FROM coffee WHERE type LIKE '$type'";
$result = mysql_query($query) or die(mysql_error());
$coffeeArray = array();
//Get data from database.
while ($row = mysql_fetch_array($result)) {
$id = $row[0];
$name = $row[1];
$type = $row[2];
$price = $row[3];
$roast = $row[4];
$country = $row[5];
$image = $row[6];
$review = $row[7];
$ide = $row[8];
//Create coffee objects and store them in an array.
$coffee = new CoffeeEntity($id, $name, $type, $price, $roast, $country, $image, $review);
array_push($coffeeArray, $coffee);
}
//Close connection and return result
mysql_close();
return $coffeeArray;
}
And here is the final php that connects:
<?php
$title = "Manage coffee objects";
include './Controller/CoffeeController.php';
$coffeeController = new CoffeeController();
$content = $coffeeController->CreateOverviewTable();
if(isset($_POST['types']))
{
//Fill page with coffees of the selected type
$coffeeTables = $coffeeController->CreateCoffeeTables($_POST['types']);
}
else
{
//Page is loaded for the first time, no type selected -> Fetch all types
$coffeeTables = $coffeeController->CreateCoffeeTables('%');
}
if(isset($_GET["delete"]))
{
$coffeeController->DeleteCoffee($_GET["delete"]);
}
include './Template.php';
?>
Any suggestions are welcome. What I want is to include an input and a type to search in each column of the table.