By kingto on
hello, i'm using a db_query for listing the nodes that website users posted.
<?php
// Recent News Nodes
$nlimit = 8;
$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n WHERE n.status = 1 AND (n.type = 'node' OR n.type = 'node') AND n.uid = %d ORDER BY n.created DESC"), $account->uid, 0, $nlimit);
$headeroutput = '<div>' . t('title) . "</div>";
$listoutput = node_title_list($result);
if($listoutput != theme('node_list', '', NULL)){
print $headeroutput;
print '<div class="user-field-title">' . $listoutput . '</div>';
}
?>
however, if the user hasn't posted any nodes yet, the list will display nothing but a blank only.
can anyone tell me what i should add into the query so that it will automatically add 'none' for the empty db_query, thanks a lot.
Comments
i wonder someone can help me,
i wonder someone can help me, many thx
See this page
See this page http://drupal.org/node/236969
Steve Turnbull, D8 developer
Like Science Fiction, Fantasy or Steampunk stories? Check out https://taupress.com/book-list
thanks for your
thanks for your help!
however, i added
into my db_query, but it did't work.
how should i modify my db_query codes?
sorry for my poor PHP skill
You can't modify the SQL
You can't modify the SQL query to do what you want.
The problem I have is the code you have put in your messages is full of mistakes. So I really don't know whether you've ever had any code that works properly, I could give you advice but if you can't write code that is syntactically correct there's no point.
The key point is that you run the query, test to see if it has any results or not, if it does have results list them, if it doesn't print the message.
The page I gave you tells you how to test for results in a couple of ways. There is no easy solution and I'm not going to write it for you.
Steve Turnbull, D8 developer
Like Science Fiction, Fantasy or Steampunk stories? Check out https://taupress.com/book-list
thx for your help. i think i
thx for your help.
i think i should try to use another way to display the node lists.