PHP join constructs SQL query Statement _php Tutorial

Source: Internet
Author: User
The join () function combines array elements into a single string.

The join () function is an alias for the implode () function.

Example

$arr = Array (' Hello ', ' world! ', ' beautiful ', ' day! ');
echo Join ("", $arr);
?> output:

Hello world! Beautiful day!

The following is a DEDECMS search page condition takes advantage of the Join function

if ($this->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)");

It makes up a select * from table where condition, based on how much $ksql is constructed into a complete SQL query statement

Note: Join () can receive two parameter sequences. But for historical reasons, explode () is not working. You must ensure that the separator parameter is not preceded by a string parameter.

The tables in the database tutorial can be linked by keys. The primary key (primary key) is a column, and the value of each row in the column is unique. In the table, the value of each primary key is unique. The purpose of this is to cross-bind the data between tables without repeating all the data in each table.

http://www.bkjia.com/PHPjc/631346.html www.bkjia.com true http://www.bkjia.com/PHPjc/631346.html techarticle the Join () function combines array elements into a single string. The join () function is an alias for the implode () function. Example PHP Tutorial $arr = array (' Hello ', ' world! ', ' beautiful ', ' day! '); echo Join ...

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