$sql=mysql_query("select max(YR_SC),CODE,PAR,PRC_N,PRC_U from bse_prc_p where CDE_L='".substr($code,0,11)."'");$row=mysql_fetch_array($sql) $row=mysql_fetch_assoc($sql);要先这样 看下手册这两个函数的用法 <?php echo $row['YR_SC']; ?>
$sql=mysql_query("select max(YR_SC) as MaxYR_SC,CODE,PAR,PRC_N,PRC_U from bse_prc_p where CDE_L='".substr($code,0,11)."'"); while($row=mysql_fetch_array($sql)){ echo $row['MaxYR_SC']; }
$sql=mysql_query("select max(YR_SC),CODE,PAR,PRC_N,PRC_U from bse_prc_p where CDE_L='".substr($code,0,11)."'"); while($row=mysql_fetch_array($sql)){ $rows[] = $row; } print_r($rows); //查看数组的结构把所有的记录保存为一个二维数组 用foreach for循环就能得到所有的值
$sql=mysql_query("select YR_SC ,CODE,PAR,PRC_N,PRC_U from bse_prc_p a where CDE_L='".substr($code,0,11)."' and not exists (select 1 from bse_prc_p where CDE_L = a.CDE_L and yr_sc > a.yr_sc)"); while($row=mysql_fetch_row($sql)){ echo $row[0]; echo $row[1]; echo $row[2]; echo $row[3]; echo $row[4];}
and not exists (select 1 from bse_prc_p where CDE_L = a.CDE_L and yr_sc > a.yr_sc)"); 不存在CDE_L相同但yr_sc更大的记录---那这条就是最大的。 慢的话可以在 CDE_L上建索引试试。
<?php echo $row['YR_SC']; ?>
while($row=mysql_fetch_array($sql)){
echo $row['MaxYR_SC'];
}
$sql=mysql_query("select max(YR_SC),CODE,PAR,PRC_N,PRC_U from bse_prc_p where CDE_L='".substr($code,0,11)."'");
while($row=mysql_fetch_array($sql)){
$rows[] = $row;
}
print_r($rows); //查看数组的结构把所有的记录保存为一个二维数组 用foreach for循环就能得到所有的值
$sql=mysql_query("select YR_SC ,CODE,PAR,PRC_N,PRC_U from bse_prc_p a where CDE_L='".substr($code,0,11)."' and not exists (select 1 from bse_prc_p where CDE_L = a.CDE_L and yr_sc > a.yr_sc)");
while($row=mysql_fetch_row($sql)){
echo $row[0];
echo $row[1];
echo $row[2];
echo $row[3];
echo $row[4];}
不存在CDE_L相同但yr_sc更大的记录---那这条就是最大的。
慢的话可以在 CDE_L上建索引试试。