Block with biblio records by author (was how to query title from record)

meles - June 3, 2008 - 19:44
Project:Bibliography Module
Version:5.x-1.15
Component:Miscellaneous
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Description

Thank you for your guidance. I have moved this to a new 'issue'. [But it's really more a need to understand.]

My goal is to display an author's pubs in a block on the author's page. I would like the title to be a URL, but that's for another day.
With your advice about the node table, I got a mysql command line query to pull out the correct records.
On the web page, I get a blank display. This is the code in the test page (right now it's a page)(input format is PHP code):

<?php
$query
= "SELECT node.title, biblio.biblio_year from node,biblio where node.type="biblio" and node.vid=biblio.vid and biblio.biblio_authors like '%someAuthorName%' ORDER BY biblio_year desc";

$result = db_query($query);

while (
$term = db_fetch_object($result)) {   
   
$term[] = array($row->title, $row->biblio_year);
}
$output = theme($rows);
return
$output;
?>

[I am using an actual author name in the query]
The problem may lie in my understanding of how PHP handles the returned results, or how Drupal themes them, or... ?
I've been studying biblio.module to see how you handle the return from db_fetch_object() but I'm not sure what's going on.

If this is better discussed elsewhere, please advise.

Thank you.

-------

The title of the publication is stored in the {node} table. The secondary title field contains different things depending on the type of publication (Series Title, Book Title, Journal Title, Conference Name etc.)

Try...
SELECT title, biblio_authors, biblio_secondary_title, biblio_year
FROM node n LEFT JOIN biblio b n.vid = b.vid
WHERE biblio_authors like '%whoever%' and n.type='biblio'
ORDER BY biblio_year desc"

Ron.

P.S. If you have any further comments/questions on this topic, please open a new issue as this is somewhat off the topic of the original issue.

#1

rjerome - June 3, 2008 - 20:34

I think there are a few problems with your PHP code. The following taken out of the biblio_block function at line 1892 of biblio.module... This will give you an html formated list in the $block['content'] variable. (And it includes title links)

<?php
  $query
= "SELECT node.title, biblio.biblio_year from node,biblio where node.type="biblio" and node.vid=biblio.vid and                                biblio.biblio_authors like '%someAuthorName%' ORDER BY biblio_year desc";

 
$result = db_query($query);
  if (
db_num_rows($result)) {
       
$base variable_get('biblio_base', 'biblio');
       
$block['subject'] = t(variable_get('biblio_block_title', 'New Publications'));
       
$block['content'] .= '<div class="item-list"><ul>';
        while (
$pub = db_fetch_object($result)) {
         
$block['content'] .= '<li >' . l("$pub->title", "node/$pub->nid") . '('. $pub->year. ')</li>';
        }
       
$block['content'] .= '</ul></div>';
      }
      return
$block;
?>

#2

meles - June 3, 2008 - 21:52

Thanks for that detailed advice. It's not displaying anything, but I'm learning just from reading the code.
I have to switch to another project for a few days but will keep at it & let you know if I solve it.

#3

meles - July 9, 2008 - 18:51

Here is what I ended up doing for now, in case it could be useful to someone.

Approach: make a block, put the code below in the body, select 'show only on certain pages', and enter the url for the author's personal page.

the block code:

<?php
   
$theName
= 'somename';
$theBaseURL = "http://somesite.org";

$result = db_query("SELECT node.nid, node.title, biblio.biblio_year from {node} node INNER JOIN {biblio} biblio ON node.nid=biblio.nid where node.type='Biblio' and biblio.biblio_authors like '%%%s%%' ORDER BY biblio_year desc", $theName);

if (
db_num_rows($result) > 0 ) {

    while (
$fetchedResult = db_fetch_object($result)) {

         
$theTitle = $fetchedResult->title;
         
$theNID = $fetchedResult->nid;
         
$theYear = $fetchedResult->biblio_year;

        
$content = sprintf('%s, %s<br />', l($theTitle, $theBaseURL .'/node/'.$theNID), $theYear);
          echo
$content;
    }
}
?>

 
 

Drupal is a registered trademark of Dries Buytaert.