Extract all the parts to be executed

Source: Internet
Author: User
Extract the part to be executed every time out of php. There are three functions in total, and the vast majority of them are the same. How can we become a function more scientifically to achieve efficiency. Method 1: how can we convert these three functions into one? Method 2: The execution body of the three functions is the public part of the output. How can this problem be achieved ????? Function & nbsp; wc1 ($ SQL) {$ tb = 'extract the part to be executed each time
In php, there are three functions with the same scores. How can we become a function more scientifically to achieve efficiency.
Method 1: how can we convert these three functions into one?
Method 2: The execution body of the three functions is the public part of the output. How can this problem be achieved ?????

Function wc1 ($ SQL ){

$ Tb = '';
$ ShowArr = array ();
$ Q = $ this-> getAll3 ($ SQL );
While ($ r = $ q-> fetch_array (MYSQLI_USE_RESULT )){
$ Tb. =''. $ R ["number"].'';
$ Tb. = isset ($ this-> show ["customer"])? ''. $ R ["customer"].'': NULL;
$ Tb. = isset ($ this-> show ["orderNo"])? ''. $ R ["orderNo"].'': NULL;


}
Return $ tb;
}
Function wc2 ($ SQL ){

$ Tb = '';
$ ShowArr = array ();
$ Q = $ this-> getAll3 ($ SQL );
While ($ r = $ q-> fetch_array (MYSQLI_USE_RESULT )){
$ Tb. =''. $ R ["number"].'';
$ Tb. = isset ($ this-> show ["customer"])? ''. $ R ["customer"].'': NULL;
$ Tb. = isset ($ this-> show ["orderNo"])? ''. $ R ["orderNo"].'': NULL;
$ Tb. = isset ($ this-> show ["name"])? ''. $ R ["name"].'': NULL;
$ Tb. = isset ($ this-> show ["wc"])? ''. $ R ["wc"].'': NULL; // ---------------- changes here

}
Return $ tb;
}
Function wc3 ($ SQL ){

$ Tb = '';
$ ShowArr = array ();
$ Q = $ this-> getAll3 ($ SQL );
While ($ r = $ q-> fetch_array (MYSQLI_USE_RESULT )){
$ Tb. =''. $ R ["number"].'';
$ Tb. = isset ($ this-> show ["customer"])? ''. $ R ["customer"].'': NULL;
$ Tb. = isset ($ this-> show ["orderNo"])? ''. $ R ["orderNo"].'': NULL;
$ Tb. = isset ($ this-> show ["name"])? ''. $ R ["name"].'': NULL;
$ Tb. = isset ($ this-> show ["fsaww"])? ''. $ R ["sfs3"].'': NULL; // ---------------- changes here

}
Return $ tb;
}

------ Solution --------------------
Function wc ($ SQL ){
$ Tb = '';
$ ShowArr = array ();
$ Q = $ this-> getAll3 ($ SQL );
$ Dict = array ('fsaww '=> 'sfs3'); // the comparison table is shown here.
While ($ r = $ q-> fetch_array (MYSQLI_USE_RESULT )){
$ Tb. =''. $ R ["number"].'';
Foreach ($ this-> show as $ k ){
If (isset ($ dict [$ k]) $ k = $ dict [$ k];
$ Tb. =''. $ R [$ k].'';
}
}
Return $ tb;
}

------ Solution --------------------
 function wc1($sql, $assoc = array()){

$tb='';
$showArr = array();
$q=$this->getAll3($sql);
while ($r=$q->fetch_array(MYSQLI_USE_RESULT)) {
$tb.=''.$r["number"].'';
if(count($assoc)){
foreach($keys as $k => $v){
$tb .= isset($this->show[$k]) ?''.$r[$v].'':NULL;
}
}
}
return $tb;
}

wc1($sql, array('customer' => 'customer', 'orderNo' => 'orderNo'));
wc1($sql, array('customer' => 'customer', 'orderNo' => 'orderNo', 'name' => 'name', 'wc' => 'wc'));
wc1($sql, array('customer' => 'customer', 'orderNo' => 'orderNo', 'name' => 'name', 'fsaww' => 'sfs3'));

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.