所以我有这个代码,我很困惑。我需要先按最早的日期排序,但我找不到任何难以解决的问题?
<?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]<=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]<=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]<=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]<=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]<=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>";
}
}
答案 0 :(得分:0)
这是一大堆代码...
如果您的问题是如何以特定顺序从数据库查询中返回一组行...
在SQL文本的 ORDER BY
子句中指定所需的序列。
假设professional_license
是DATE
或DATETIME
列,并且您希望首先使用该列中最旧的值返回查询中的行,那么您的查询将看起来像这样:
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
子句中指定您希望结果集“按顺序排列”的表达式。
(如果你问的是另一个问题,那就不清楚了。)
答案 1 :(得分:0)
HI在您的查询中,只使用orderby子句作为ORDER BY date asc