Home > Backend Development > PHP Tutorial > php join constructs sql query statement_PHP tutorial

php join constructs sql query statement_PHP tutorial

WBOY
Release: 2016-07-13 16:59:08
Original
1024 people have browsed it

join() function combines array elements into a string.

join() function is an alias of 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 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 select * from table where condition, which is constructed into a complete sql query statement according to the amount of $ksql

Note: join() can receive two parameter orders. However, due to historical reasons, explode() does not work. You must ensure that the separator parameter comes before the string parameter.

Tables in the database tutorial can be linked to each other by keys. The primary key is a column in which the value of each row is unique. In a table, each primary key value is unique. The purpose of this is to cross-bundle data between tables without duplicating all the data in each table.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631346.htmlTechArticlejoin() function combines array elements into a string. The join() function is an alias of the implode() function. Example ?php tutorial $arr = array('hello','world!','beautiful','day!'); echo join...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template