Mam wyszczególnione usługi z bazy danych które dodaję do tabeli zlecenia (usługa, ilość, wartość), usługi wyświetlają się w postaci kafelków jeden pod drugim co jest fajne do sklepu z produktami gdzie widzisz opis, fotkę i cenę a ja chciałbym żeby wybór był z listy rozwijalnej i nie wiem jak przerobić ten kod mimo kilku dni prób :-(
<?php
session_start();
$connect = mysqli_connect("localhost", "root", "", "baza");
if(isset($_POST["add_to_cart"]))
{
if(isset($_SESSION["shopping_cart"]))
{
$item_array_id = array_column($_SESSION["shopping_cart"], "item_id");
if(!in_array($_GET["id"], $item_array_id))
{
$count = count($_SESSION["shopping_cart"]);
$item_array = array(
'item_id' => $_GET["id"],
'item_name' => $_POST["hidden_name"],
'item_price' => $_POST["hidden_price"],
'item_quantity' => $_POST["quantity"]
);
$_SESSION["shopping_cart"][$count] = $item_array;
}
else
{
echo '<script>alert("Item Already Added")</script>';
echo '<script>window.location="index.php"</script>';
}
}
else
{
$item_array = array(
'item_id' => $_GET["id"],
'item_name' => $_POST["hidden_name"],
'item_price' => $_POST["hidden_price"],
'item_quantity' => $_POST["quantity"]
);
$_SESSION["shopping_cart"][0] = $item_array;
}
}
if(isset($_GET["action"]))
{
if($_GET["action"] == "delete")
{
foreach($_SESSION["shopping_cart"] as $keys => $values)
{
if($values["item_id"] == $_GET["id"])
{
unset($_SESSION["shopping_cart"][$keys]);
echo '<script>window.location="index.php"</script>';
}
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Zlecenie</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
</head>
<body>
<br />
<div class="container" style="width:700px;">
<h3 align="center">Zlecenie</h3><br />
<?php
$query = "SELECT * FROM uslugi ORDER BY rodzaj ASC";
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
?>
<div class="col-md-4">
<form method="post" action="index.php?action=add&id=<?php echo $row["ID_uslugi"]; ?>">
<div style="border:1px solid #333; background-color:#f1f1f1; border-radius:5px; padding:16px;" align="center">
<h4 class="text-info"><?php echo $row["rodzaj"]; ?></h4>
<h4 class="text-danger"><?php echo $row["wartosc"]; ?> PLN</h4>
<input type="text" name="quantity" class="form-control" value="1" />
<input type="hidden" name="hidden_name" value="<?php echo $row["rodzaj"]; ?>" />
<input type="hidden" name="hidden_price" value="<?php echo $row["wartosc"]; ?>" />
<input type="submit" name="add_to_cart" style="margin-top:5px;" class="btn btn-success" value="Dodaj" />
</div>
</form>
</div>
<?php
}
}
?>
</div><br>
<div style="clear:both"></div>
<br />
<h3>Szczegóły zlecenia</h3>
<div class="table-responsive">
<table class="table table-bordered">
<tr>
<th width="40%">Usługa</th>
<th width="10%">Ilość</th>
<th width="20%">Wartość usługi</th>
<th width="15%">Koszt usługi</th>
<th width="5%"></th>
</tr>
<?php
if(!empty($_SESSION["shopping_cart"]))
{
$total = 0;
foreach($_SESSION["shopping_cart"] as $keys => $values)
{
?>
<tr>
<td><?php echo $values["item_name"]; ?></td>
<td align="center"><?php echo $values["item_quantity"]; ?></td>
<td align="right"><?php echo $values["item_price"]; ?> PLN</td>
<td align="right"><?php echo number_format($values["item_quantity"] * $values["item_price"], 2); ?> PLN</td>
<td align="center"><a href="index.php?action=delete&id=<?php echo $values["item_id"]; ?>"><span class="text-danger">Usuń</span></a></td>
</tr>
<?php
$total = $total + ($values["item_quantity"] * $values["item_price"]);
}
?>
<tr>
<td colspan="3" align="right">Koszt zlecenia</td>
<td align="right"><?php echo number_format($total, 2); ?> PLN</td>
<td></td>
</tr>
<?php
}
?>
</table>
</div>
</div>
<br />
</body>
</html>