您希望在存档页面上显示价格和产品名称"添加到图表"按钮。 我想用这段代码做这件事。但我只得到或者价格或名称。
<?php
require_once '../includes/init.php';
$id = $_POST['Productid'];
$id = (int)$id;
$sql = "SELECT * FROM Products WHERE Productid = '$id'";
$result = $db->query($sql);
$product = mysqli_fetch_assoc($result);
$brand_id = $product['Brand'];
$sql = "SELECT Brand FROM Brand WHERE Brandid = '$brand_id'";
$brand_query = $db->query($sql);
$brand = mysqli_fetch_assoc($brand_query);
$sizestring = $product['Size'];
//$sizestring = ($sizestring,',');
$size_array = explode(',' , $sizestring);
?>
<?php ob_start(); ?>
<div class="modal fade detail-1" id="details-modal" tabindex="-1" role="dialog" aria-labelledby="detail-1" aria-hidden="true">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<!--***CLOSING MODAL CLASS****-->
<button type="button" class="close" aria-label="Close" onclick="closeModal()">
<span aria-hidden="true">×</span>
</button>
<h3 class="modal-title">
<?php echo $product['Name']; ?></h3>
</div>
<div class="modal-body">
<div class="container-fluid">
<div class="row">
<span id="modal_errors" class="bg-danger"></span>
<div class="col-sm-6">
<div class="center-block">
<img src="
<?php echo $product['Image'];?>" alt="
<?php echo $product['Name'];?>" class="img-fluid"/>
</div>
</div>
<div class="col-sm-6">
<h3>
Details
</h3>
<p>
<?php echo nl2br($product['Description']); ?></p>
<p>
Price: Ksh.
<?php echo $product['UnitPrice']; ?></p>
<p>
Brand:
<?php echo $brand['Brand']; ?></p>
<form action="add_cart.php" method="POST" id="add_product_form">
<input type="hidden" name="product_id" value="
<?php echo$id;?>">
<input type="hidden" name="available" id="available" value="">
<div class="form-group">
<label for="quantity">Quantity:</label>
<input type="number" class="form-group" id="quantity" name="quantity" min="0">
<br/>
</div>
<div class="form-group">
<label for="size">Size:</label>
<select name="size" id="size" name="size" class="form-control">
<option value=""></option>
<?php foreach($size_array as $string){
$string_array = explode(':', $string);
$size = $string_array[0];
$available = $string_array[1];
echo '<option value="'.$size.'" data-available="'.$available.'">'.$size.' (Available: '.$available.')</option>';
}?>
</select>
</div>
</form>
</div>
</div>
</div>
</div>
<div class="modal-footer" style="height:90px;">
<button type="button" class="btn btn-secondary" onclick="closeModal()" style="margin-top:0px;">Close</button>
<button type="button" class="btn btn-warning" onclick="add_to_cart();return false;" style="margin-top:0px;">
<span class="glyphicon glyphicon-shopping-cart">Add To Cart</span>
</button>
</div>
</div>
</div>
</div>
<script>
//event listener
jQuery('#size').change(function(){
var available = jQuery('#size option:selected').data("available");
jQuery('#available').val(available);
}
);
function closeModal(){
jQuery('#details-modal').modal('hide');
setTimeout(function(){
jQuery('#details-modal').remove();
jQuery('.modal-backdrop').remove();
}
,500);
}
</script>
<?php echo ob_get_clean(); ?>
我知道&#34; get_price()&#34;会得到我的价格。