Aşağı açılır menüden birden fazla seçeneği nasıl hesaplayacağımı sormak istiyorum.Seçme seçenek açılır menüsünden birden fazla değer hesaplanıyor
Buraya basit html kodunu ve PDO işlevlerinden işlev ekleyeceğim. Ne istediğim <div id="RightBox">
değerleri <div id="LeftBox">
nolu javascript düğmelerinden taşındı ve sonra değerlerini $value = explode('|', $_GET['service'])
ile patlattıktan sonra hesaplama ile hesaplamaktır. Bu değerleri patlattığımda . $vysledek["Service_price"] .
işlevini Typ() işlevinden almak istiyorum ve Bu değerlerin bu $calculation = (2 * $height * ($lenght + $width) + ($lenght+ $width)) * $value[1];
deseniyle. Ben sadece bir tane seçildim (sonuncusu) Ama herşeyin işe yaramasını istiyorum, böylece her servis türü için $calculation
modeli kullanılacaktır ve daha sonra tüm hesaplamalar numaralanacak ve daha sonra nihai fiyatı ekleyecektir. Gerçekten nasıl yapacağımı bilmiyorum belki bana yardım edebilirsin. Teşekkür ederim.
HTML:
<div id="Calkulator">
<form>
<h2>Calculator</h2>
<table cellspacing="5" cellpadding="5">
<tbody>
<tr>
<td><label for="lenght">Lenght of room in m2: </label></td>
<td><input type="number" class="text_field small" id="lenght_of_room" min="1" name="lenght"></td>
</tr>
<tr>
<td><label for="width">Width of room in m2: </label></td>
<td><input type="number" class="text_field small" id="width_of_room" min="1" name="width"></td>
</tr>
<tr>
<td><label for="height">Height of room in m2: </label></td>
<td><input type="number" class="text_field small" id="height_of_room" min="1" name="height"></td>
</tr>
<tr>
<td><label for="typ">Service type: </label></td>
<td>
<div id="LeftBox">
<select id="leftValues" size="8" multiple>
<?php
require_once 'funkce.php';
$database = new Database();
$database->Typ();
?>
</select>
</div>
<div id="Buttons">
<input type="button" id="btnLeft" value="<<" />
<input type="button" id="btnRight" value=">>" />
</div>
<div id="RightBox">
<select id="rightValues" name="service" size="8" multiple>
</select>
</div>
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" class="submit" value="Count">
<div class="clear"></div>
</td>
</tr>
<tr>
<td colspan="2"></td>
</tr>
</tbody>
</table>
<?php
$height = $_GET[height];
$lenght = $_GET[lenght];
$width = $_GET[width];
$value = explode('|', $_GET['service']);
var_dump($value);
$calculation = (2 * $height * ($lenght + $width) + ($lenght+ $width)) * $value[1];
echo "<p>Price: $calculation Kč</p>";
?>
</form>
</div>
</div>
PDO PHP: Fonksiyon Tipi
public function Typ() {
try {
$stmt = $this->conn->prepare("SELECT Service_name , Service_price FROM Service_type");
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($result as $vysledek){
echo '<option value="' . $vysledek["Service_name"] . "|" . $vysledek["Service_price"] . '">' . $vysledek["Service_name"] . '</option>';
}
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
$this->conn = null;
}
Eğer seçim kutusunun altında seçilen değerleri toplamak istersiniz? – ameenulla0007
RightBox'a eklenen değerleri, yani sağ kutudaki tüm değerleri toplamlamak istiyorum. Sağ kutuya eklenen bu tip hizmetler, kullanıcı seçtiğinde daha farklı fiyatlara sahip olur. hangi.. $ vysledek ["Service_price"] ile temsil edilen Typ() işlevindedir. veritabanından. ve daha sonra Hizmet türünün her biri için hesaplamayı kullanın ve ardından fiyatların tümünü bir son fiyat olarak hesaplayın. –
yup, daha sonra cevabımı aşağıdan kontrol edin ve çok önemlisi seçmeniz gereken her bir sağ taraflı seçeneği yapmak için JS'yi kullanmanız gerekiyor, 'selected' özniteliği – ameenulla0007