讀到這篇教學怎樣用code 來替代views
http://drupaltaiwan.org/forum/20080507/2068
按著最簡單的
<?php
$result = db_query_range("SELECT n.nid, n.title FROM {node} n WHERE n.type = 'eventshow' ORDER BY n.created DESC", 10);
while ($test = db_fetch_object($result)) {
echo l($test->title,'node/'.$test->nid).'<br/>';
};
?>未有任何問題,但當我在SELECT 時加入 n.body , 即是
.......................("SELECT n.nid, n.title, n.body FROM {node} n ..................
echo l($test.body);就顯示不到任何內容
就


Re: 用code 來替代views
因為 body 欄位並不在 node 表裡面阿~
Re: 用code 來替代views
那應該怎樣做??
Re: 用code 來替代views
body 欄位在 node_revisions 表中~
SQL 語法應該不用我提供吧?簡單的兩張表作 JOIN 就行了
Re:
谢谢~~~~~~
------------------
還有一個問題,我創建的content type 其中有一個是imagefield 的field, 但在node_revisions 找不到這個field
請問自訂content type 的CCK field怎樣retreive 出來?
我條sql 是這樣的
$sql = "SELECT n.nid, n.title, n_rev.body FROM {node} n LEFT JOIN {node_revisions} n_rev ON n.nid = n_rev.nid WHERE n.type = 'eventshow'";經過研究, sql 修正如下
$sql = "SELECT n.nid, n.title, imgphoto.field_photo_title, n_rev.body FROM {node} n LEFT JOIN {node_revisions} n_rev ON n.nid = n_rev.nid INNER JOIN {content_field_photo} imgphoto ON n.nid = imgphoto.nid WHERE n.type = 'eventshow' ORDER BY n.created DESC";問題是只知道 image field 的文件名 ( 是用這個field, field_photo_title 來讀取filename 嗎? ), 但怎樣只道images 的儲存路徑?
用hard code ? 比如
<img src="/files/$xxxxxxx" />或有更好的方法
Re:
現在寫的code是顯示正常的,可顯示圖片
$sql = "SELECT n.nid, n.title, imgphoto.field_photo_title, n_rev.body FROM {node} n LEFT JOIN {node_revisions} n_rev ON n.nid = n_rev.nid INNER JOIN {content_field_photo} imgphoto ON n.nid = imgphoto.nid WHERE n.type = 'eventshow' ORDER BY n.created DESC";$result = db_query_range($sql,10);
while ($test = db_fetch_object($result)) {
echo '<img src=' . base_path() . file_directory_path() . '/' . $test->field_photo_title . '><br/>';
echo $test->body . '<br/>';
};
但好像作法有點hard coded
coding 有更好的寫法嗎?? 比如現在不能用imagecache 的縮圖來顯示

結果就像這樣子
Re: 用code 來替代views
用 theme_image 如何?
http://api.drupal.org/api/function/theme_image/5