php join 構造sql查詢語句_PHP教程

來源:互聯網
上載者:User
join() 函數把數組元素組合為一個字串。

join() 函數是 implode() 函數的別名。

例子

$arr = array('hello','world!','beautiful','day!');
echo join(" ",$arr);
?>輸出:

hello world! beautiful day!

下面是一段dedecms搜尋網頁面的條件利用了join函數

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)" );

它這裡就構成了一條select * from 表 where 條件,根據$ksql多少來構造成一條完整的sql查詢語句

注釋:join() 可以接收兩種參數順序。但是由於曆史原因,explode() 是不行的。你必須保證 separator 參數在 string 參數之前才行。

資料庫教程中的表可通過鍵將彼此聯絡起來。主鍵(primary key)是一個列,在這個列中的每一行的值都是唯一的。在表中,每個主鍵的值都是唯一的。這樣做的目的是在不重複每個表中的所有資料的情況下,把表間的資料交叉捆綁在一起。

http://www.bkjia.com/PHPjc/631346.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/631346.htmlTechArticlejoin() 函數把數組元素組合為一個字串。 join() 函數是 implode() 函數的別名。 例子 ?php教程 $arr = array('hello','world!','beautiful','day!'); echo join...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.