打印多列单独
问题描述:
使用下面的查询:打印多列单独
SELECT title, nid, created FROM node WHERE uid = $account->uid ORDER BY changed DESC
我该如何去有关打印标题,NID,分别创建(在PHP)?
谢谢! (我确信这很简单,我只是不习惯PHP)
答
这是一个非常基本的问题,试试谷歌的教程。下面是关于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'];
答
如果您希望只有一个结果:
$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 />';
}