gpt4 book ai didi

javascript - 如果月份与特定月份匹配,则在选择某个月份时尝试显示多行数据

转载 作者:行者123 更新时间:2023-11-27 22:58:11 25 4
gpt4 key购买 nike

当我点击某个月份时,例如一月。然后它应该显示从一月份开始的数据库中的所有数据。每隔一个月都一样。我正在使用 PHP、JavaScript、HTML 和 CSS 来执行此操作。我最初有一种工作方式,但它只会显示该月特定的 1 条数据,当更改为类元素时,它停止工作。目前,没有任何显示,点击月份时也没有错误返回。

PHP:

if($row['month'] === 'January'){

echo '<div class="rallyPrintJanuary">';
echo "<h2>" . $row['rallyVenue'] . " in " . $row['month'] . " " . $row['year'] . "</h2>";
echo "<h4>Event: ". $row['rallyEvent'] . " </h4>";
echo "<h3>Your Marshall(s): " . $row['rallyMarsh'] . "</h3>";
echo "<h4>When? ". $row['rallyDate'] . " </h4>";
echo "<p>" . $row['rallyDesc'] . "</p>";
echo "<p>How much? ". $row['rallyCost'] . " </p>";
echo "<p>How long? ". $row['rallyNights'] . " Nights</p>";
echo "<p>Pitch Limit? ". $row['pitchLimit'] . "</p>";
echo "<p>Phone Number: 0". $row['phoneNo'] . " </p>";
echo "<p>Email: <a href='mailto:". $row['email'] . "'> ". $row['email'] ."</a></p>";
echo "<p>Please make sure you to contact ". $row['rallyMarsh'] . " for more information.</p>";
if(isset($_SESSION['loggedin'])){
echo "<a href='' id='". $row['rallyId'] . "' class='trash'>Delete</a>";
}
echo "</div><br>";
}

HTML:

<div class="calander-container">
<div class="months">
January
</div>
<div class="months">
February
</div>
<div class="months">
March
</div>
<div class="months">
April
</div>
<div class="months">
May
</div>
<div class="months">
June
</div>
<div class="months">
July
</div>
<div class="months">
August
</div>
<div class="months">
September
</div>
<div class="months">
October
</div>
<div class="months">
November
</div>
<div class="months">
December
</div>
</div>

JavaScript:

    document.addEventListener("DOMContentLoaded", function(event) {
let monthArray = document.querySelectorAll(".months");

monthArray.forEach(function(monthh){
monthh.addEventListener("click", (e) => {
const monthName = document.getElementsByClassName("months").textContent;
const months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
months.forEach(month => {

const el = document.getElementsByClassName('rallyPrint' + month);

if (monthName === month) {

el[0].style.display = "block"; // Show current month

}else if(!month){
el[0].style.display = "none"; //Not the current month, hide
}


});
});
});
});

最佳答案

你有数据库吗? $row[] 函数从表中选择一行。所以你需要一个数据库。还有当你做 if($row['month'] === 'January')这就像在说 if(table Month === January) {}你真的不能说 Table 是否等于这个东西,例如January 做这个表并不真正等于任何东西,也许是表中的某些东西而不是表本身。哦,还有你在 JS 中拼写错误的月份可能想要解决这个问题。最后但并非最不重要的另一个原因是你的东西可能没有打印是因为你做了这个 echo "<h2>" . $row['rallyVenue'] . " in " . $row['month'] . " " . $row['year'] . "</h2>";我想打印这样一行你可能会喜欢这样的东西 echo '<p class="UserPost">' . $row["MainPagePosts"] . " | Posted By: " . $row["PostUser"] . "</p>";

关于javascript - 如果月份与特定月份匹配,则在选择某个月份时尝试显示多行数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59136792/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com