smarty?SQL

WBOY
Release: 2016-06-23 13:27:47
Original
1091 people have browsed it

public functions getName(){   $sql=sprintf("select pin,point from table");   $results = array();   if(!$error=$this->db->query($sql)) {      $name = $this->getSn($results['pin']);      $this->hlist[] = $results;   }   $this->db->free();   $this->db2->free();   return $this->hlist;}public function getSn($pin){   $sql = sprintf("SELECT sn FROM `%s_pin` WHERE pin=%s",__MYSQL_PREFIX,$pin);   return $this->db2->get_one($sql);}
Copy after login

在sql执行过程中执行另一条sql.原本getSn里的db2是写成db,但发现查出来的数据只有1条,所以才加个db2
现在sql是没问题了,但打开页面的时间好久,请问要怎么优化??


回复讨论(解决方案)

$this->db2-> get_one($sql)
从方法的命名上看,就是取一条记录

$this->db2-> get_one($sql)
从方法的命名上看,就是取一条记录



Table
series(数据表): id(字段) name
category: id seriesid name
$sql=sprintf("select id,seriesid,name from category"); if(!$error=$this->db->query($sql)) {      $name = $this->getName($results['seriesid']);      $results['seriesid']=$name['name'];      $this->hlist[] = $results;   } return $this->hlist;//我想把从category表里读取出来的seriesid替换成对应的名字//但是用这种方法,在页面打开的时候要等很久,请问可以怎么优化??function getName($seriesid){   $sql=sprintf("select name from series where id=$seriesid");   return $this->db2->get_one($sql);}
Copy after login

你确定页面慢是这段代码的问题吗?

自己先检查一下看是哪里慢。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template