【发布时间】:2018-06-16 21:31:26
【问题描述】:
好吧,我在每个网站上都进行了搜索,但没有找到我想要的内容: 我会让你更容易,看看我有什么: my page ;)
所以对于每个单选按钮,我想设置我的表格的显示。
例如:如果我选择“Alphabétique”,则值按字母顺序排序。
我知道我需要使用 Ajax,但我对此绝对不满意。除此之外,我还在 MVC 中编写我的项目。 我对 Google、Stack、OpenClassroom 等进行了一些研究。 而且我不完全了解我需要在 Ajax 中做什么,或者我需要在哪里添加说明。 所以这是我的代码:
controllerBoutique.php(控制器):
<?php
require('../Views/codes/boutique.php');
require('../Models/vehicule.php');
$query = getVehiculesByAlpha();
require('../Views/codes/tabAffich.php');
?>
boutique.php:(查看)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Rentcar - Boutique</title>
<link rel="stylesheet" href="../Views/styles/style2.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js'></script>
</head>
<body>
<?php require("menu.php");?>
<section id="section" class="main-section cleanbg">
<div class="container">
<label>Trier par :</label>
<div class="single-col">
<div class="styled-input-container">
<div class="styled-input-single">
<input type="radio" name="fieldset-1" id="radioAlpha" value="Alpha" checked="checked"/>
<label for="radioAlpha">Alphabétique</label>
</div>
<div class="styled-input-single">
<input type="radio" name="fieldset-1" id="radioModel" value ="Model"/>
<label for="radioModel">Modèle</label>
</div>
<div class="styled-input-single">
<input type="radio" name="fieldset-1" id="radioKm" value ="Km"/>
<label for="radioKm">Kilométrage</label>
</div>
<div class="styled-input-single">
<input type="radio" name="fieldset-1" id="radioDispo" value ="Dispo"/>
<label for ="radioDispo"> Disponible </label>
</div>
</div>
</div>
</div>
<div class="search">
<label class="lblSearch"> Rechercher :</label>
<input type="text" id="search-box" class="search-box">
<button class="btnSearch">Chercher</button>
</div>
</section>
<section id="section" class="main-section cleanbg">
<div class="container">
<hr>
tabAffich.php : (查看表格)
<div class="wrapper">
<div class="table">
<div class="row header">
<div class = "cell">Marque</div>
<div class = "cell">Modèle</div>
<div class= "cell">Kilométrage</div>
</div>
<?php
while($res = $query->fetch()){
?>
<div class="row">
<div class ="cell">
<?php echo $res['nom'];?>
</div>
<div class="cell">
<?php echo $res['modele'];?>
</div>
<div class="cell">
<?php echo $res['km'];?>
</div>
</div>
<?php
}
$query->closeCursor();
?>
</div>
</div>
</div>
</section>
</body>
</html>
vehicule.php(型号):
<?php
function getVehiculesByAlpha(){
try{
$db = new PDO('mysql:host=localhost;dbname=ProjectRentcar;charset=utf8','root','root');
}catch(Exception $e){
die('Erreur : '.$e->getMessage());
}
$query = $db->query('
SELECT nom, modele, km
FROM Vehicule V, Marque Ma
WHERE V.numMarque = Ma.numMarque
ORDER BY nom, modele');
return $query;
}
function getVehiculesByModel(){
//Same code with order differently
}
function getVehiculesByKm(){
//Same here
}
所以我会知道如何在单击特定单选按钮时更改表格的显示,以及 Ajax 中的一些帮助 ???? 提前谢谢你❤️
【问题讨论】:
标签: javascript php jquery ajax radio-button