<?php
$str_sql="select * from day_data where year=2660 and month=9";
$result=mysql_query($str_sql) or die(mysql_error()); while ($record = mysql_fetch_object($result)) 
{
if ($record->day >= 15 && $record->day <=17)
{
echo  $record->day.":".$record->counts."<br>";
}
else
{
echo "<br>";
}
}?>

解决方案 »

  1.   

    while ($record = mysql_fetch_object($result)) 这个就判断了,你去的9月的全部纪录,显示一条,然后下一条,如果没有了,就推出这个while了,如果9月有31条,那么,就循环了31次
      

  2.   

    while ($record = mysql_fetch_object($result)) 
    {
    if ($record->day >= 15 && $record->day <=17)
    {
    echo  $record->day.":".$record->counts."<br>";
    }
    else
    {
    echo  $record->day.":0<br>";
    }
    }
      

  3.   

    其他要如何显示,你改 else
    {
    echo "<br>";
    }中间的就可以了。
      

  4.   

    <?php
    $str_sql="select * from day_data where year=2660 and month=9";
    $result=mysql_query($str_sql) or die(mysql_error()); while ($record = mysql_fetch_object($result)) 
    {
    $date[$record->day] = $record->counts;
    }
    for($i = 1;$i <= 31;$i++)
    {
    if (!empty($date[$i]))
    {
    echo $i.":".$date[$i]."<br>";
    }
    else
    {
    echo $i.":0<br>";
    }
    }
    ?>