diff --git a/add_offer.php b/add_offer.php new file mode 100644 index 0000000..60ae9d4 --- /dev/null +++ b/add_offer.php @@ -0,0 +1,61 @@ + + + + + + + + + + + + + +
+
+
+ +

Board

+ + + + + +
+
+ + +
+

Enter your offer

+
+ + Quality
+
+
+ Amount you can deliver
+
+
+ Name your price
+
+
+ Description
+
+ +
+
+ + + diff --git a/functions.php b/functions.php index aaf7507..73860e0 100644 --- a/functions.php +++ b/functions.php @@ -209,7 +209,11 @@ function show_demand () echo "

Description:
"; - echo $demand_rows->demandText; + echo "$demand_rows->demandText

"; + echo "
+ + +
"; } function post_offer() @@ -217,15 +221,53 @@ function post_offer() if (isset($_POST['submit'])) { global $con; $userId = get_userid(); + $demandId = $_POST['demandId']; $pieces = $_POST['pieces']; $price = $_POST['price']; $qualityId = $_POST['quality']; $text = $_POST['text']; // Inserts Data into Database - $sql = "INSERT INTO offers (pieces, text, price, userId, qualityId) - VALUES ('$pieces', '$text', '$price', '$userId', '$qualityId')"; + $sql = "INSERT INTO offers (pieces, text, price, userId, qualityId, + demandId) + VALUES ('$pieces', '$text', '$price', '$userId', '$qualityId', + '$demandId')"; $result = mysqli_query($con, $sql) or die(mysqli_error($con)); } } +function show_offer () +{ + global $con; + $demandId = $_POST['demandId']; + + // get the offers matching the demand from the database + $offer_query = "SELECT * FROM offers where demandId='$demandId'"; + $offer_query_result = mysqli_query($con, $offer_query) or + die(mysqli_error($con)); + + // if the query on the database returned data print the data + while ($offer_rows = $offer_query_result->fetch_object()) { + $qualityId = $offer_rows->qualityId; + $quality_query = "SELECT * FROM quality where qualityId='$qualityId'"; + $quality_query_result = mysqli_query($con, $quality_query) or + die(mysqli_error($con)); + $quality_rows = $quality_query_result->fetch_object(); + + echo "Offer Nr: " . $offer_rows->offerId; + echo "
+
"; + echo "Amount available: " . $offer_rows->pieces; + echo "
+
"; + echo "Price per piece: " . $offer_rows->price; + echo "
+
"; + echo "Provided Quality: " . $quality_rows->qualityName; + echo "
+
+ Description:
"; + echo $offer_rows->text . "
+
"; + } +} ?> diff --git a/show_demand.php b/show_demand.php index 97dc1d6..c13f7c7 100644 --- a/show_demand.php +++ b/show_demand.php @@ -31,9 +31,8 @@ include 'functions.php'; show_demand(); ?>
-
-
- -
+ diff --git a/sql/create_db.sql b/sql/create_db.sql index b704731..0182030 100644 --- a/sql/create_db.sql +++ b/sql/create_db.sql @@ -60,14 +60,16 @@ CREATE TABLE if not exists `offers` ( `text` text CHARACTER SET utf8 COLLATE utf8_bin, `price` float NOT NULL, `pieces` int(11) NOT NULL, - `delivery` bool NOT NULL, `date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `userId` int(11) NOT NULL, `qualityId` int(11) NOT NULL, + `demandId` int(11) NOT NULL, CONSTRAINT `fk_offers_userId` FOREIGN KEY (userId) REFERENCES users (userId), - CONSTRAINT `fk_offers_qualityId` - FOREIGN KEY (qualityId) REFERENCES quality (qualityId) + CONSTRAINT `fk_offers_qualityId` + FOREIGN KEY (qualityId) REFERENCES quality (qualityId), + CONSTRAINT `fk_offers_demandId` + FOREIGN KEY (demandId) REFERENCES demands (demandId) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;