这个要看你的具体语句了。 否则没办法给你什么建议。比如你有很多 select * from table1 where id=1, select * from table1 where id=2则建议你运行一句 select * from table1 where id=1 or id=2
if($conn){ //echo "connect success<br>"; mysql_query("SET NAMES 'GBK'"); $recode="select * from hgf where strcmp(la,$realtime)>0 and strcmp(la,$date1)<0"; $result=mysql_query($recode,$conn); $num_rows = mysql_num_rows($result);//acheiece recode //echo $num_rows; $recodee="select distinct si,sp,di,dp,proto from hgf where strcmp(la,'$realtime')>0 and strcmp(la,'$date1')<0"; //echo $recodee; $resultt = mysql_query($recodee,$conn); $num_rowss = mysql_num_rows($resultt); //echo $num_rowss; $tcprecode="select * from hgf where proto='TCP' and strcmp(la,'$realtime')>0 and strcmp(la,$date1)<0"; $tcpresult=mysql_query($tcprecode,$conn); $tcp_num_rows = mysql_num_rows($tcpresult); $tcppercent=$tcp_num_rows/$num_rows*100;//achieve tcp percent num $udprecode="select * from hgf where proto='UDP' and strcmp(la,'$realtime')>0 and strcmp(la,$date1)<0"; $udpresult=mysql_query($udprecode,$conn); $udp_num_rows = mysql_num_rows($udpresult); $udppercent=$udp_num_rows/$num_rows*100;//achieve udp percent num $clientrecode="select distinct si from hgf where strcmp(la,'$realtime')>0 and strcmp(la,$date1)<0"; $clientresult=mysql_query($clientrecode,$conn); $client_num_rows = mysql_num_rows($clientresult);//achiece clients num 这就是我上面的查询语句,我觉得太繁琐了,要怎么改进呢?就是这样多次查询数据库好么??
select * from table1 where id=1,
select * from table1 where id=2则建议你运行一句 select * from table1 where id=1 or id=2
if($conn){
//echo "connect success<br>";
mysql_query("SET NAMES 'GBK'");
$recode="select * from hgf where strcmp(la,$realtime)>0 and strcmp(la,$date1)<0";
$result=mysql_query($recode,$conn);
$num_rows = mysql_num_rows($result);//acheiece recode
//echo $num_rows;
$recodee="select distinct si,sp,di,dp,proto from hgf where strcmp(la,'$realtime')>0 and strcmp(la,'$date1')<0";
//echo $recodee;
$resultt = mysql_query($recodee,$conn);
$num_rowss = mysql_num_rows($resultt);
//echo $num_rowss;
$tcprecode="select * from hgf where proto='TCP' and strcmp(la,'$realtime')>0 and strcmp(la,$date1)<0";
$tcpresult=mysql_query($tcprecode,$conn);
$tcp_num_rows = mysql_num_rows($tcpresult);
$tcppercent=$tcp_num_rows/$num_rows*100;//achieve tcp percent num
$udprecode="select * from hgf where proto='UDP' and strcmp(la,'$realtime')>0 and strcmp(la,$date1)<0";
$udpresult=mysql_query($udprecode,$conn);
$udp_num_rows = mysql_num_rows($udpresult);
$udppercent=$udp_num_rows/$num_rows*100;//achieve udp percent num
$clientrecode="select distinct si from hgf where strcmp(la,'$realtime')>0 and strcmp(la,$date1)<0";
$clientresult=mysql_query($clientrecode,$conn);
$client_num_rows = mysql_num_rows($clientresult);//achiece clients num
这就是我上面的查询语句,我觉得太繁琐了,要怎么改进呢?就是这样多次查询数据库好么??