Php join to construct an SQL query statement

Source: Internet
Author: User

The join () function combines array elements into a string.

The join () function is the alias of the implode () function.

Example

<? Php tutorial
$ Arr = array ('hello', 'World! ', 'Beautiful', 'day! ');
Echo join ("", $ arr );
?> Output:

Hello world! Beautiful day!

The following is a dedecms search page condition using 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 forms a where Condition for the select * from table, which is used to construct a complete SQL query statement based on the number of $ ksql statements.

Note: join () can receive two parameter sequences. However, explode () cannot be used for historical reasons. You must ensure that the separator parameter is prior to the string parameter.

 

Tables in the database tutorial can be linked by keys. A primary key is a column in which the values of each row are unique. In the table, the values of each primary key are unique. In this way, the data in each table is bundled together without repeating all the data in each table.

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.