php如何这么查询数据库并把结果echo
发布网友
发布时间:2022-04-06 03:52
我来回答
共2个回答
热心网友
时间:2022-04-06 05:21
<?php
mysql_connect('127.0.0.1','root','123456');
$sql='select id,num from db.table';
$res=mysql_query($sql);
$num2='';
echo 'id num 大小<br>';
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 '<br>';
$num2=$row['num'];
}
mysql_free_result($res);
mysql_close();
?>
热心网友
时间:2022-04-06 06:39
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做