SQL Statement Optimization

Source: Internet
Author: User
$searchlist = Array ("id" = 3, "id2" = +, "flat" = 1), array ("id" = 5, "id2" = 6, "flat"    = 1), array ("id" = 2, "id2" = 3, "flat" = 2), array ("id" = 9, "id2" = 1, "flat" = 2), Array ("id" = 6, "Id2" = 4, "flat" = 1), "$searchresult =" "; foreach ($searchlist as $k = + $v) {if ($v [' flat '] = = 1) {$sql = sprintf ("Select Insurance_entitle1 as Title1 from%s_insurance where insurance_id =%d", $this-&gt        ; Tablepre, $v [' id ']);        $result = $this->db->get_one ($sql); $searchresult [$k] [' title1 '] = isset ($result [' title1 '])?        $result [' Title1 ']: ""; $sql = sprintf ("Select Insurance_encontent as content from%s_insurance_section where insurancese_section=%d order by Insu        Rancese_order ", $this->tablepre, $v [' id ']);        $result = $this->db->get_one ($sql); $searchresult [$k] [content] = Isset ($result [' content '])?        $result [' content ']: ""; $searchresult [$k] [' flat '] = $v[' flat '];    $searchresult [$k] [' id '] = $v [' id ']; }elseif ($v [' flat '] = = 2) {$sql = sprintf ("Select Insurance_entitle1 as Title1 from%s_insurance where insurance_id        =%d ", $this->tablepre, $v [' Id2 ']);        $result = $this->db->get_one ($sql); $searchresult [$k] [' title1 '] = isset ($result [' title1 '])?        $result [' Title1 ']: ""; $sql = sprintf ("Select Insurance_encontent as content from%s_insurance_section where insurancese_id=%d order by insurance        Se_order ", $this->tablepre, $v [' id ']);        $result = $this->db->get_one ($sql); $searchresult [$k] [content] = Isset ($result [' content '])?        $result [' content ']: "";        $searchresult [$k] [' flat '] = $v [' flat '];        $searchresult [$k] [' id '] = $v [' id '];    $searchresult [$k] [' sid '] = $v [' Id2 ']; }}


Reply to discussion (solution)

Don't see SQL, just see PHP

  • 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.