Construct an SQL query statement using phpjoin

Source: Internet
Author: User
The join () function combines array elements into a string. the join () function is the alias of the implode () function, for example, the following code :? The php $ arrarray (n... join () function combines array elements into a string. the join () function is the alias of the implode () function, for example, the following code:

 

The following is a condition on the dedecms search page that uses the join function:

 starttime > 0) {    $ksqls[] = " arc.senddate>'" . $this->starttime . "' ";}if ($this->typeid > 0) {    $ksqls[] = " typeid in (" . getsonids($this->typeid) . ") ";}if ($this->channeltype > 0) {    $ksqls[] = " arc.channel='" . $this->channeltype . "'";}if ($this->mid > 0) {    $ksqls[] = " arc.mid = '" . $this->mid . "'";}$ksqls[] = " arc.arcrank > -1 ";$this->addsql = ($ksql == '' ? join(' and ', $ksqls) : join(' and ', $ksqls) . " and ($ksql)");?>

Here it forms a where condition for the select * from table and constructs a complete SQL query statement based on the number of $ ksql statements.

Note:Join () can receive two parameter sequences, but explode () cannot be used due to historical reasons. you must ensure that the separator parameter is prior to the string parameter.

In the database tutorial, tables can be connected by keys. the primary key is a column, and the values of each row in this column are unique. in the table, the values of each primary key are unique. the purpose of this operation is to combine the data in different tables without repeating all the data in each table.

Link to this article:

Add to favorites ^ please keep the tutorial address.

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.