简要说明一下,我了解我的PHP代码很杂乱,我知道可以使用数组修复很多问题。
因此,此页面用于显示存储在多个表中的车辆详细信息,记录将等于1或2。1为是具有此功能,而2为否没有。然后在以后的样式中,我检查它是否等于1,如果等于1,则显示一些文本,以便用户可以看到车辆具有的功能。我的样式在文本旁边打印了一个蓝色的勾号,以使其看起来不错。仅当车辆具有功能时才打印此报价,但由于某种原因,它会随机打印报价。两者都不匹配,因此在我的代码中,如果车辆没有5件事,那么它可能只会打印1个空白滴答声或2个空白滴答声,这是不一致的,而且我不知道为什么!
初始PHP代码
//Fetch Category - Most Popular
$queryThree = "SELECT * FROM categoryMostPopular WHERE vehicleReg = :reg";
$stmt = $conn->prepare($queryThree);
$stmt->bindValue(':reg', $vehicleReg);
$stmt->execute();
$category1 = $stmt->fetch(PDO::FETCH_ASSOC);
//Put Results Into Variables
$mostPopularReg = $category1['vehicleReg'];
$airCon = $category1['airCon'];
$bluetooth = $category1['bluetooth'];
$climateControl = $category1['climateControl'];
$satNav = $category1['satNav'];
$commsPack = $category1['commsPack'];
$climateZonex2 = $category1['climateZonex2'];
$dvdPlayer = $category1['dvdPlayer'];
$fullLeather = $category1['fullleather'];
$halfLeather = $category1['halfLeather'];
$ipodConnectivity = $category1['ipodConnectivity'];
$manufacturersDirect = $category1['manufacturersDirect'];
$memorySeats = $category1['memorySeats'];
$panarRoof = $category1['panarRoof'];
$elecFoldingMirrors = $category1['elecFoldingMirrors'];
$rainSenseWipers = $category1['rainSenseWipers'];
$xenonHeadlights = $category1['xenonHeadlights'];
我之所以没有发布所有初始的PHP代码,主要是因为我有12个与上述相同的类别,所以代码很多。
检查IF变量设置为1还是2,然后显示刻度和文本
<div class="col-sm-6">
<ul class="fa-ul list-unstyled">
<?php
if ($alcantaraLeather == 1) { echo "<li><i class='fa-li fa fa-check'></i>Alcantara Leather</li>"; }
if ($clothUpholstery == 1) { echo "<li><i class='fa-li fa fa-check'></i>Cloth Upholstery</li>"; }
if ($velourTrim == 1) { echo "<li><i class='fa-li fa fa-check'></i>Velour Trim</li>"; }
if ($fullLeather == 1) { echo "<li><i class='fa-li fa fa-check'></i>Full Leather</li>"; }
if ($halfLeather == 1) { echo "<li><i class='fa-li fa fa-check'></i>Half Leather</li>"; }
if ($elecFoldingMirrors == 1) { echo "<li><i class='fa-li fa fa-check'></i>Electric Folding Mirrors</li>"; }
if ($rainSenseWipers == 1) { echo "<li><i class='fa-li fa fa-check'></i>Rain Sense Wipers</li>"; }
if ($xenonHeadlights == 1) { echo "<li><i class='fa-li fa fa-check'></i>Xenon Headlights</li>"; }
if ($electricSeats == 1) { echo "<li><i class='fa-li fa fa-check'></i><li><i class='fa-li fa fa-check'></i>Electric Seats</li>"; }
if ($frontCentreArmrest == 1) { echo "<li><i class='fa-li fa fa-check'></i><li><i class='fa-li fa fa-check'></i>Front Centre Armrest</li>"; }
if ($headRestraints == 1) { echo "<li><i class='fa-li fa fa-check'></i><li><i class='fa-li fa fa-check'></i>Head Restraints</li>"; }
if ($heatedSeats == 1) { echo "<li><i class='fa-li fa fa-check'></i><li><i class='fa-li fa fa-check'></i>Heated Seats</li>"; }
?>
</ul>
</div> <!-- end .col-sm-6 -->
如果有人可以看看为什么出现随机滴答声,我将非常感激。
After making adjustments to the code, as mentioned by another user. This is my result
答案 0 :(得分:0)
可能是您的样式表(CSS文件)将'li'标记默认为刻度。在chrome上,默认值为项目符号点。
因此,创建一个CSS文件并更改'li'标签的样式。
希望这会有所帮助。
element.style {
}
user agent stylesheet
li {
display: list-item;
text-align: -webkit-match-parent;
}
答案 1 :(得分:0)
我认为您可以在这里进行一些改进。
在编程中,当您处理“全有或全无”条件(布尔值)时,应将0表示NO(或FALSE),将1表示YES(或TRUE)。
< / li>在某些行中有两个<li>
,例如“电子座椅”。
if
语句将隐藏整个文本。您只需要将if语句包装在复选标记周围。<?= $variable; ?>
将这些建议应用于您的代码后,您会得到...
<div class="col-sm-6">
<ul class="fa-ul list-unstyled">
<?php
$checkMark = "<i class='fa-li fa fa-check'></i> "; // Leave the extra trailing space in this string.
?>
<?php if($alcantaraLeather == 1): ?><li><?= $checkMark; ?>Alcantara Leather</li><?php endif; ?>
<?php if($clothUpholstery == 1): ?><li><?= $checkMark; ?>Cloth Upholstery</li><?php endif; ?>
<?php if($velourTrim == 1): ?><li><?= $checkMark; ?>Velour Trim</li><?php endif; ?>
<?php if($fullLeather == 1): ?><li><?= $checkMark; ?>Full Leather</li><?php endif; ?>
<?php if($halfLeather == 1): ?><li><?= $checkMark; ?>Half Leather</li><?php endif; ?>
<?php if($elecFoldingMirrors == 1): ?><li><?= $checkMark; ?>Electric Folding Mirrors</li><?php endif; ?>
<?php if($rainSenseWipers == 1): ?><li><?= $checkMark; ?>Rain Sense Wipers</li><?php endif; ?>
<?php if($xenonHeadlights == 1): ?><li><?= $checkMark; ?>Xenon Headlights</li><?php endif; ?>
<?php if($electricSeats == 1): ?><li><?= $checkMark; ?>Electric Seats</li><?php endif; ?>
<?php if($frontCentreArmrest == 1): ?><li><?= $checkMark; ?>Front Centre Armrest</li><?php endif; ?>
<?php if($headRestraints == 1): ?><li><?= $checkMark; ?>Head Restraints</li><?php endif; ?>
<?php if($heatedSeats == 1): ?><li><?= $checkMark; ?>Heated Seats</li><?php endif; ?>
</ul>
</div> <!-- end .col-sm-6 -->