English 中文(简体)
采用PHP的查询,以最佳方式从我的桌上印刷价值
原标题:Best way to print values from mysql table by querying through PHP
  • 时间:2010-03-13 09:43:44
  •  标签:
  • php
  • mysql

在我几页的大部分时间里,我只需要用一种 lo机在表格中打印一个领域的价值。 例如:

 <?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+记录,上述休息时间将达到5 000+倍。

将<条码>工业/代码>外地的数值从<条码>表_工业/条码>上删除的最佳方式是什么?

这部法典是上文提到的,还是有加快执行的方法?

最佳回答

JOIN

如果你只想把那些在工业上具有价值观的行文包括在内。 之后的图表

    SELECT 
     table_prof.profid 
    , table_prof.name 
    , table_industry.industry  
      FROM table_prof 
      JOIN table_industry USING ( profid ) 
      ORDER BY table_prof.name ASC;

并且如果你想把所有数值列入表table_prof 然后, s子

      SELECT 
     table_prof.profid 
    , table_prof.name 
    , table_industry.industry  
      FROM table_prof 
      LEFT JOIN table_industry USING ( profid ) 
      ORDER BY table_prof.name ASC;

i 认为这将有助于你......

问题回答
  1. Avoid looping over all 5000 records. Use a filtering or pagination
  2. Even more avoid nested queries. Use power of JOIN.

我最好的猜测是,JOIN

<join 您可以指示MySQL服务器将不同的表格合并在一起,并在单一询问中查阅,例如:

SELECT
  table_prof.profid
, table_prof.name
, table_industry.industry 
FROM table_prof
JOIN table_industry USING ( profid )
ORDER BY table_prof.name ASC;

一般来说,将数据库放在空档中是一个非常坏的想法,应当避免,除非你确切知道为什么要这样做。 住宿条件可以很容易地将数据库服务器带给它。

遵循你的逻辑,即选择它的所有信息载荷,在散列,而不是杀害数据库。





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签