Display a list of a user´s content

Last modified: January 8, 2007 - 21:28

This scripts shows a list of a user´s content (from a specific content element), with a link to directly edit or delete the content. (Note: after a content has been deleted by pressing the delete link, a "page cannot be found" will be displayed.)

<?php
 
// Show users content ------------------------------------------
 
$title = 'Your stories'; //title, change this
 
$nocontent = ''; //message if there is no conent
 
$type = "story"; //type of content
 
$nlimit = 50; //maximum objects to show


  // this box will not be shown unless user has created some content
 
unset($output);
  global
$user;

 
// show only for logged in
 
if ($user->uid>0){
 

   
//sql ------------------------------------------------------ 
   
$sql = "SELECT n.created, n.title, n.nid, n.changed, n.type, n.status
            FROM node n
            WHERE n.status = 1 AND n.uid = $user->uid AND n.type = '"

   
$sql .= $type;
   
$sql .= "'
            ORDER BY n.changed
            DESC LIMIT $nlimit"
;

   
$result = db_query($sql);



   
$co = 0;
   
$output='';
   
$output .= '<TABLE BORDER="1" CELLPADDING="1"  CELLSPACING="3" WIDTH="100%"><TR><TD BGCOLOR="#f5f4f4">
'
;

   
$co = 0;
    while (
$anode = db_fetch_object($result)) {
      
$co++;
      
$output .= "<li>"
      
.l("Edit", "node/$anode->nid/edit")." - "
      
.l("Delete", "node/$anode->nid/delete")." - "
      
.l($anode->title, "node/$anode->nid").
      
"</li>";
    }
   
   
$output .= '</TD></TR></TABLE><BR>';
   
//show only if user have made some content
   
if ($co>0){
      print
$title;
      print
$output;
    }
    if (
$co == 0 AND $nocontent<>""){
      print
$nocontent;
      print
'<BR><BR>';
    }

    unset (
$output);
  }
?>

 
 

Drupal is a registered trademark of Dries Buytaert.