Smarty? Sql

Source: Internet
Author: User
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);}

Execute another SQL during SQL execution. The original GETSN in the DB2 is written in db, but found that the data only 1, so add a DB2
Now SQL is no problem, but open the page for a long time, ask how to optimize??


Reply to discussion (solution)

$this->db2-> Get_one ($sql)
From the name of the method, it is to take a record

$this->db2-> Get_one ($sql)
From the name of the method, it is to take a record



Table
Series (data sheet): ID (field) 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;//I want to replace the SERIESID from the category table with the corresponding name//But in this way, when the page is opened to wait a long time, how can I optimize?? function GetName ($seriesid) {   $sql =sprintf ("Select name from series where id= $seriesid");   return $this->db2->get_one ($sql);}

Are you sure that the page is slow is a problem with this code?

Check yourself first to see where it is slow.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.