gpt4 book ai didi

php - 通过 PHP 查询从 mysql 表打印值的最佳方法

转载 作者:行者123 更新时间:2023-11-29 03:55:27 25 4
gpt4 key购买 nike

大多数时候,在我的页面中,我只需要使用循环打印表中一个字段的值。例如:

 <?php

for($i=1;$i<=mysql_num_rows($result);$i++)
{
echo $row['name'];
$sql1="select industry from table_industry where profid='".$row['prof']."'";
$result1=mysql_query($sql1);
$row1=mysql_fetch_array($result1);
echo $row1['industry']; ?>
}
?>

例如,我在表中有 5000+ 条记录,上面的循环将执行 5000+ 次。

从表 table_industry 中打印 industry 字段值的最佳方法是什么?

是我上面写的代码,还是有更快执行的方法?

最佳答案

  1. 避免遍历所有 5000 条记录。使用过滤或分页
  2. 更要避免嵌套查询。使用JOIN的力量。

关于php - 通过 PHP 查询从 mysql 表打印值的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2437887/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com