add function to show the details of a demand

This commit is contained in:
Andreas Zweili 2017-03-01 21:59:56 +01:00
parent 4b7a290527
commit ae050b7923
2 changed files with 94 additions and 23 deletions

View File

@ -97,30 +97,35 @@ function post_demand ()
// A function to insert the own posts from the database into the website
function get_demand_titles ()
{
global $con;
$sql = "SELECT * FROM demands";
$result = mysqli_query($con, $sql);
while ($row = $result->fetch_assoc()) {
echo "<div class='post-box'><p>";
echo "<a href='show_demand.php'><strong>" . $row['demandTitle'] .
"</strong></a>" . "<br>";
echo $row['date'] . "<br>";
echo "<form class= 'delete-form' method= 'POST'
action='".delete_demand()."'>
<input type='hidden' name='demandId' value='".$row['demandId']."'>
<button type='submit' name= 'deletepost'> Delete</button>
</form>
global $con;
$sql = "SELECT * FROM demands";
$result = mysqli_query($con, $sql);
while ($row = $result->fetch_assoc()) {
echo "<div class='post-box'><p>";
echo "<strong>" . $row['demandTitle'] . "</strong></a>" . "<br>";
echo $row['date'] . "<br>";
<form class= 'edit-form' method= 'POST' action='edit_demand.php'>
<input type='hidden' name='userId' value='".$row['userId']."'>
<input type='hidden' name='demandId' value='".$row['demandId']."'>
<input type='hidden' name='piecesMax' value='".$row['piecesMax']."'>
<input type='hidden' name='piecesMin' value='".$row['piecesMin']."'>
<input type='hidden' name='title' value='".$row['demandTitle']."'>
<input type='hidden' name='text' value='".$row['demandText']."'>
<button>Edit</button>
</form>
</div>";
echo "<form class= 'delete-form' method= 'POST'
action='".delete_demand()."'>
<input type='hidden' name='demandId' value='".$row['demandId']."'>
<button type='submit' name= 'deletepost'> Delete</button>
</form>";
echo "<form method= 'POST' action='show_demand.php'>
<input type='hidden' name='demandId' value='".$row['demandId']."'>
<button>Show Details</button>
</form>";
echo "<form class= 'edit-form' method= 'POST' action='edit_demand.php'>
<input type='hidden' name='userId' value='".$row['userId']."'>
<input type='hidden' name='demandId' value='".$row['demandId']."'>
<input type='hidden' name='piecesMax' value='".$row['piecesMax']."'>
<input type='hidden' name='piecesMin' value='".$row['piecesMin']."'>
<input type='hidden' name='title' value='".$row['demandTitle']."'>
<input type='hidden' name='text' value='".$row['demandText']."'>
<button>Edit</button>
</form>
</div>";
}
}
@ -167,4 +172,35 @@ function delete_demand()
}
}
function show_demand ()
{
global $con;
$demandId = $_POST['demandId'];
$demand_query = "SELECT * FROM demands where demandId='$demandId'";
$demand_query_result = mysqli_query($con, $demand_query) or
die(mysqli_error($con));
$demand_rows = $demand_query_result->fetch_object();
$qualityId = $demand_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 "<h2>" . $demand_rows->demandTitle . "</h2>";
echo "<br>
<br>";
echo "<strong>Maximum required pieces: </strong>" . $demand_rows->piecesMax;
echo "<br>
<br>";
echo "<strong>Minimumrequired pieces: </strong>" . $demand_rows->piecesMin;
echo "<br>
<br>";
echo "<strong>Quality: </strong>" . $quality_rows->qualityName;
echo "<br>
<br>
<strong>Description:</strong><br>";
echo $demand_rows->demandText;
}
?>

35
show_demand.php Normal file
View File

@ -0,0 +1,35 @@
<?php
include 'functions.php';
?>
<!DOCTYPE html>
<html>
<head>
<!-- enable utf-8 encoding for umlauts etc.-->
<meta charset="utf-8">
<!-- Description of what this dose -->
<meta name ="viewport" content="width=device-width, initial-scale=1">
<!-- link to the default css file -->
<link rel="stylesheet" href="css/stylesheet.css"/>
</head>
<body>
<div>
<header>
<!-- The sidebar naviagtion begins here -->
<nav>
<?php
include 'navigation.php';
?>
</nav>
<!-- The sidebar naviagtion ends here -->
</header>
</div>
<!-- The Post function begins here -->
<div class='post-box'><p>
<?php
show_demand();
?>
</div>
</body>
</html>