mysql_connect('127.0.0.1','root','123456');
$sql='select id,num from db.table';
$res=mysql_query($sql);
$num2='';
echo 'id num 大小
';
while($row=mysql_fetch_array($res)){
echo $row['id'];
echo ' ';
echo $row['num'];
echo ' ';
if ($row['num']>$num2) echo '大';
elseif ($row['num']<$num2) echo '小';
else echo '同';
echo '
';
$num2=$row['num'];
}
mysql_free_result($res);
mysql_close();
?>
select a.id,CONCAT(
if(a.num = b.num,'同',''),
if(a.num > b.num,'大',''),
if(a.num < b.num,'小','')
) as echo
from table a
left join table b on a.id = (b.id-1)
试下这句 sql,有时候 能交给sql做的事情,就让sql做