Druap6資料庫存取範例

You are viewing a wiki page. You are welcome to join the group and then edit it. Be bold!

本文適用於drupal6

範例說明

這個範例程式將示範Drupal網站中所有page內容類型的文章之title。藉此初步瞭解如何對drupal資料庫進行存取。

使用方式

本文的程式碼可以直接在node中使用。

在你的Drupal網站中新增一個內容節點(node),在建立畫面中的內容區塊(body)中貼上文末的程式碼。

範例程式碼

<?php

//設定要餵進sql字串的參數
$type = 'page';//參數一(本範例只有一個參數)

//執行SQL,Drupal將重新處理sql字串,MySql將看見的是SELECT title FROM node WHERE type = 'page'
//string用%s
//Integer用%d
//Float用%f
$result = db_query("SELECT title FROM {node} WHERE type = '%s'", $type);
$count=0;

while($data=db_fetch_object($result)){
echo $count.")".$data->title."<br>";
$count++;
}

?>

Taiwan

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week