收藏,好好研究一下
十分感谢这位老大 ToT
<?
function mysql_result_all($result,$format="") {
echo "<table $format><tr>";
for($i=0;$i<mysql_num_fields($result);$i++) {
echo "<th>".mysql_field_name($result,$i)."</th>";
}
echo "</tr>";
while($row = mysql_fetch_row($result)) {
echo "</tr>";
for($i=0;$i<mysql_num_fields($result);$i++) {
echo "<td>".$row[$i]."</td>";
}
echo "</tr>";
}
echo "</table>";
}
?>
十分感谢这位老大 ToT
<?
function mysql_result_all($result,$format="") {
echo "<table $format><tr>";
for($i=0;$i<mysql_num_fields($result);$i++) {
echo "<th>".mysql_field_name($result,$i)."</th>";
}
echo "</tr>";
while($row = mysql_fetch_row($result)) {
echo "</tr>";
for($i=0;$i<mysql_num_fields($result);$i++) {
echo "<td>".$row[$i]."</td>";
}
echo "</tr>";
}
echo "</table>";
}
?>
mysql_query("select @v:=(@v+1) as xh, id from data HAVING mod(xh,$pagesize)=0 order by id $order");比较,第一个也应该比第二个快很多吧.
还有,刚才查了一下手册,上面说"limit会在一些情况下用到索引",如果他用了索引方法一的查询速度应该和方法二的速度是接近的.但是他会在什么情况下用索引呢. 上面说的"一些情况"是指什么啊?
下面是手册里写的,迷惑, 如果可以用到索引的话,那么两种方法的速度就应该是一样了吧?呵呵.10.5.5 MySQL怎样优化LIMIT
在一些情况中,当你使用LIMIT #而不使用HAVING时,MySQL将以不同方式处理查询。 如果你用LIMIT只选择一些行,当MySQL一般比较喜欢做完整的表扫描时,它将在一些情况下使用索引。
如果你使用LIMIT #与ORDER BY,MySQL一旦找到了第一个 # 行,将结束排序而不是排序整个表。
当结合LIMIT #和DISTINCT时,MySQL一旦找到#个唯一的行,它将停止。
在一些情况下,一个GROUP BY能通过顺序读取键(或在键上做排序)来解决,并然后计算摘要直到键值改变。在这种情况下,LIMIT #将不计算任何不必要的GROUP。
只要MySQL已经发送了第一个#行到客户,它将放弃查询。
LIMIT 0将总是快速返回一个空集合。这对检查查询并且得到结果列的列类型是有用的。
临时表的大小使用LIMIT #计算需要多少空间来解决查询。
老大换成这样会不会好点
<?
function mysql_result_all($result,$format="") {
$temp="<table $format><tr>";
for($i=0;$i<mysql_num_fields($result);$i++) {
$temp=$temp."<th>".mysql_field_name($result,$i)."</th>";
}
echo $temp."</tr>";
while($row = mysql_fetch_row($result)) {
$temp="<tr>";
for($i=0;$i<mysql_num_fields($result);$i++) {
$temp=$temp."<td>".$row[$i]."</td>";
}
$temp=$temp."</tr>";
}
echo $temp."</table>";
}
?>
Ctrl+C
老大换成这样会不会好点
<?
function mysql_result_all($result,$format="") {
$temp="<table $format><tr>";
for($i=0;$i<mysql_num_fields($result);$i++) {
$temp=$temp."<th>".mysql_field_name($result,$i)."</th>";
}
echo $temp."</tr>";
$temp='';
while($row = mysql_fetch_row($result)) {
$temp=$temp."<tr>";
for($i=0;$i<mysql_num_fields($result);$i++) {
$temp=$temp."<td>".$row[$i]."</td>";
}
$temp=$temp."</tr>";
}
echo $temp."</table>";
}
?>
mysql_query("set @v:=-1"); // 定义mysql用户变量
$rs = mysql_query("select @v:=(@v+1) as xh, id from data HAVING mod(xh,$pagesize)=0 order by id $order");
谢谢!看不懂