我又被卡住了!所以,希望你们真棒的人可以帮助我......
到目前为止,我所拥有的是一个查询数据库的搜索功能,并返回结果,工作正常,然后用户可以点击其中一个结果,将其带到他们点击的新详细页面,例如一个品牌。然后在详细页面上,它返回所有品牌详细信息(使用$ _GET [' id'])和一组来自关系表的新数据,以及与之对应的所有商品的列表品牌,也有效。但后来我陷入困境,我希望用户能够点击每个优惠,并将该优惠的详细信息加载到模式中...我已尝试使用$ _GET [' id&# 39;]对于商品ID,但显然,它在同一页面上(我推测),它传递品牌/父母的ID而不是商品。
这是回复与品牌相关的所有优惠的代码
$offers_sql = 'SELECT * FROM codes WHERE client_id LIKE :client_id AND CURDATE() between start AND expiry';
$offersq = $db->prepare($offers_sql);
$offers_params = array(':client_id' => $id);
$offersq->execute($offers_params);
$results = $offersq->fetchAll(PDO::FETCH_ASSOC);
if(count($results) < 1) {
$output = "<h4>no current offers available</h4>";
}
else {
foreach($results as $r) {
$title = $r['title'];
$code = $r['textcode'];
$offer_id = $r['id'];
$expiry = $r['expiry'];
$date = new DateTime($expiry);
$output .= '<h4><a href="#?id=' . $offer_id . '" class="md-trigger" data-modal="offer">' . $title . '</a></h4><hr>';
}
}
} catch (PDOException $e) {
echo "failed to load offers";
}
?>
这是我用于模态的代码
require('inc/connect/config.php');
include('inc/result.php');
$page_title = "Title - " . $name . " Offers";
include('inc/style.php');
include('inc/header.php');
include('inc/offers.php');
?>
<!-- Intro Section -->
<section class="intro-section">
<div class="container">
<div class="row">
<div class="col-lg-12">
<h3 class="navbar-fixed-top">Latest Deals</h3>
<h1><?php echo $name; ?></h1>
</div>
</div>
</div>
</section>
<section class="offer-section">
<div class="container">
<div class="row">
<div class="col-xs-12 col-sm-6 col-sm-offset-3 col-md-6 col-md-offset-3 col-lg-6 col-lg-offset-3">
<?php echo $output; ?>
</div>
</div>
</div>
</section>
<div class="md-modal md-effect-flip" id="offer">
<div class="md-content">
<h4><?php $offer = (int) $_GET['id'];
echo $offer ?></h4>
<button type="submit" class="modal-btn md-close navbar-fixed-bottom" value="submit"><p>close</p></button>
</div>
</div>
<?php include('inc/footer.php'); ?>
返回品牌详情的代码位于单独的页面上,但如有必要,我可以包含该代码。
我做错了什么?请放轻松我,我对php比较新。
提前致谢
王小强
答案 0 :(得分:0)
Make Changes, Where Output is declared in else condition. (Changes Done)
$output='<h4><a class="OfferIdClass" data-OfferID="<?echo $offer_id;?>" href="#offer" data-modal="offer" data-toggle="modal">'.$title.'</a></h4>';
// Add This to footer.php (Changes Done)
<div class="md-modal md-effect-flip" id="offer">
<div class="md-content">
</div>
</div>
//Add this below in that page, where you are clicking Modal.
//Changes Done
<script>
$('.OfferIdClass').click(function(){
var OfferID=$(this).attr('data-OfferID');
$.ajax({url:"Open-Offer.php?OfferID="+OfferID,cache:false,success:function(result){
$(".md-content").html(result); //Here, Changes Done
}});
});
</script>
//创建一个Open-Offer.php页面。 (改变完成)
Open-Offer.php
<?
extract($_GET);
<h4><?php $offer = (int) $_GET['id'];
echo $offer ?></h4>
<button type="submit" class="modal-btn md-close navbar-fixed-bottom" value="submit"><p>close</p></button>
?>