开发者

Print multiple columns individually

开发者 https://www.devze.com 2023-02-10 04:45 出处:网络
Using the following query: SELECT title, nid, created FROM node WHERE uid = $account->uid ORDER BY 开发者_JAVA百科changed DESC

Using the following query:

SELECT title, nid, created FROM node WHERE uid = $account->uid ORDER BY 开发者_JAVA百科changed DESC

How do I go about printing the title, nid, created separately (in PHP)?

Thanks! (I'm sure this is VERY simple, I'm just not used to PHP yet)


This is a very basic question, try google for tutorials. Here's a c/p from the very first google result about PHP and mysql which shows the technique you're after.

// 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


If you expect only one result:

$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';
}

Otherwise (i reread the title of the question now, sorry)

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

精彩评论

暂无评论...
验证码 换一张
取 消