2011-02-11 78 views
-3

使用下面的查詢:打印多列單獨

SELECT title, nid, created FROM node WHERE uid = $account->uid ORDER BY changed DESC 

我該如何去有關打印標題,NID,分別創建(在PHP)?

謝謝! (我確信這很簡單,我只是不習慣PHP)

回答

1

這是一個非常基本的問題,試試谷歌的教程。下面是關於PHP和MySQL的第一個谷歌結果的c/p,它顯示了你之後的技術。

// Retrieve all the data from the "example" table 
$result = mysql_query("SELECT * FROM example") 
or die(mysql_error()); 

// store the record of the "example" table into $row 
$row = mysql_fetch_array($result); 
// Print out the contents of the entry 

echo "Name: ".$row['name']; 
echo " Age: ".$row['age']; 

http://www.tizag.com/mysqlTutorial/mysqlquery.php

0

如果您希望只有一個結果:

$query = "SELECT title, nid, created FROM node WHERE uid = '".$account->uid."' ORDER BY changed DESC"; 
$resource = mysql_query($query) or die (mysql_error()); 

if(mysql_num_rows($resource)>0) 
{ 

    $row = mysql_fetch_array($resource); 
    echo 'Title: '.$row['title'].'<br />'; 
    echo 'ID: '.$row['nid'].'<br />'; 
} 
else 
{ 
    echo 'no record found'; 
} 

否則(我重讀了問題的標題,現在,對不起)

while ($row = mysql_fetch_array($resource)) 
{ 
     echo 'Title: '.$row['title'].'<br />'; 
     echo 'ID: '.$row['nid'].'<br />'; 
}