best way to prgram php and mysql query

Posted by air on Stack Overflow See other posts from Stack Overflow or by air
Published on 2010-03-13T09:43:44Z Indexed on 2010/03/13 9:55 UTC
Read the original article Hit count: 208

Filed under:
|

most of times in our pages we need to print only 1 field value of table in loop. for example

 <?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']; ?>
 }
 ?>

above is one PHP code just for example where we think that $row['prof'] carry value of profession ID and we print profession of each person.

for example we have 5000+ record in table and above loop will execute for 5000+ times

what will be the best way to print value of industry field from table table_industry

  1. Same code which i write above ?
  2. any other php code suggestion for faster execution and less use of resources?

Thanks

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql