gpt4 book ai didi

php - 按日期对表字段进行排序 从最旧到最新

转载 作者:行者123 更新时间:2023-11-29 23:14:13 26 4
gpt4 key购买 nike

所以我有这段代码,但我很困惑。我需要先按最旧的日期对其进行排序,但我找不到任何解决方案,有什么困难吗?

<?php require_once('header.php'); ?>

<div class="nav1">
<p>Upcoming Expiration Dates</p>
</div>

<div class="data" style=" width:80%; margin:-31px auto auto 89px; ">

<ul>
<li style="font-size: 20px; background-color:#9E9494;">Name</li>
</ul>
<ul>
<li style="font-size: 20px; background-color:#9E9494;">Expire Date</li>
</ul>

<ul>
<li style="font-size: 20px; background-color:#9E9494;">License Type</li>
</ul>
<?php
/* Start Registered_Nurses */
$select="SELECT * FROM registered_nurses INNER JOIN licenses ON registered_nurses.id= licenses.id where professional_license BETWEEN '$cdate' AND DATE_ADD('$cdate', INTERVAL 135675 DAY) and '$cdate' ";
$m=mysql_query($select);
while($f=mysql_fetch_array($m))
{
if($f[6]>=$cdate)
{
echo "<ul>";
echo "<li style='background-color:#f1f1f1; '>";
echo "<a href='upcom_nurse_edit.php?id=$f[0]&lt=professional license' style='color:#6C89D1;'>$f[1]</a>";
echo "</li>";
echo "<li style='background-color:#f1f1f1; color:#6C89D1; '>";
echo $f[6];
echo "</li>";
echo "<li style='background-color:#f1f1f1; color:#6C89D1;'>";
echo "professional license";
echo "</li>";
echo "</ul>";
}
}
$select="SELECT * FROM registered_nurses INNER JOIN licenses ON registered_nurses.id= licenses.id where professional_license BETWEEN '$cdate' - INTERVAL 135675 DAY AND '$cdate' ";
$m=mysql_query($select);

while($f=mysql_fetch_array($m))
{
if($f[6]<$cdate)
{
echo "<ul>";
echo "<li style='background-color:#f1f1f1;'>";
echo "<a href='upcom_nurse_edit.php?id=$f[0]&lt=professional license' style='color:red;'>$f[1]</a>";
echo "</li>";
echo "<li style='background-color:#f1f1f1; color:red; '>";
echo $f[6];
echo "</li>";
echo "<li style='background-color:#f1f1f1; color:red;'>";
echo "professional license";
echo "</li>";
echo "</ul>";
}

}

$select1="SELECT * FROM registered_nurses INNER JOIN licenses ON registered_nurses.id= licenses.id where license_verification BETWEEN '$cdate' AND DATE_ADD('$cdate', INTERVAL 135675 DAY) and '$cdate' ";
$m1=mysql_query($select1);
while($f1=mysql_fetch_array($m1))
{
if($f1[7]>=$cdate)
{

echo "<ul>";
echo "<li style='background-color:#cccccc;'>";
echo "<a href='upcom_nurse_edit.php?id=$f1[0]&lt=License Verification' style='color:#6C89D1;'>$f1[1]</a>";
echo "</li>";
echo "<li style='background-color:#cccccc; color:#6C89D1;'>";
echo $f1[7];
echo "</li>";
echo "<li style='background-color:#cccccc; color:#6C89D1;'>";
echo "License Verification";
echo "</li>";
echo "</ul>";
}
}
$select1="SELECT * FROM registered_nurses INNER JOIN licenses ON registered_nurses.id= licenses.id where license_verification BETWEEN '$cdate' - INTERVAL 135675 DAY AND '$cdate' ";
$m1=mysql_query($select1);
while($f1=mysql_fetch_array($m1))
{
if($f1[7]<$cdate)
{

echo "<ul>";
echo "<li style='background-color:#cccccc;'>";
echo "<a href='upcom_nurse_edit.php?id=$f1[0]&lt=License Verification' style='color:red;'>$f1[1]</a>";
echo "</li>";
echo "<li style='background-color:#cccccc; color:red;'>";
echo $f1[7];
echo "</li>";
echo "<li style='background-color:#cccccc; color:red;'>";
echo "License Verification";
echo "</li>";
echo "</ul>";
}
}

$select2="SELECT * FROM registered_nurses INNER JOIN licenses ON registered_nurses.id= licenses.id where cpr BETWEEN '$cdate' AND DATE_ADD('$cdate', INTERVAL 135675 DAY) and '$cdate' ";
$m2=mysql_query($select2);
while($f2=mysql_fetch_array($m2))
{
if($f2[8]>=$cdate)
{
echo "<ul>";
echo "<li style='background-color:#f1f1f1;'>";
echo "<a href='upcom_nurse_edit.php?id=$f2[0]&lt=CPR' style='color:#6C89D1;' >$f2[1]</a>";
echo "</li>";
echo "<li style='background-color:#f1f1f1; color:#6C89D1;'>";
echo $f2[8];
echo "</li>";
echo "<li style='background-color:#f1f1f1; color:#6C89D1;'>";
echo "CPR";
echo "</li>";
echo "</ul>";
}
}

最佳答案

这是一大堆代码......

如果您的问题是如何以特定顺序从数据库查询返回一组行...

在 SQL 文本的 ORDER BY 子句中指定所需的顺序。

假设 professional_licenseDATEDATETIME 列,并且您希望查询中返回的行包含该列中最旧的值首先,您的查询将如下所示:

 SELECT ...
FROM ...
WHERE ...
ORDER BY professional_license ASC

如果您希望行按相反顺序排列,请将 ASC 替换为 DESC。可以在 ORDER BY 子句中指定多个表达式...如果两行的 professional_license 值相同,则下一个表达式将用于确定具有匹配的 值的行的顺序>professional_license 将被返回。例如:

  ORDER BY professional_license ASC, name ASC

对其他查询遵循相同的模式,在 ORDER BY 子句中指定您希望结果集“排序依据”的表达式。

(如果您问的是不同的问题,则不清楚。)

关于php - 按日期对表字段进行排序 从最旧到最新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27933705/

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