Hi,

I was wondering if there is a way to display users of a role in a table, with their profile fields, picture printed maybe using views and another module? I can program the php but it gets tedious for multiple roles.

At the moment I'm using custom php blocks to print them out.

Any help would rock!

Thanks,

Sarah

Comments

scarer’s picture

Hi,

I have written some custom code but now am having trouble trying to set data when it isn't in the database. The data form the next set of results moves over to the left. I've tried empty and isset and NULL and '' as conditions in an if else statement preceeding the while statement and it hasn't worked. Any help would be great.

This is my code:

/* This block lists the Research Fellows
 * Written by Sarah Vardy
 * Do anything you want with this
*/

$count = 0;

$result = db_query("SELECT u.uid FROM {users} u JOIN {users_roles} ur ON  u.uid = ur.uid WHERE ur.rid = '15' ORDER BY u.created ASC");
  

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

			//store uids in an array
			$uidArray[$count] = $node->uid;
			$count ++;


}//end while statement
 
print '<table cellpadding="1" cellspacing="1"><th>Photo</th><th>Name</th><th>Role</th><th>Organisation</th><th>Email</th><th>Telephone</th>';  

for ($i=0;$i<count($uidArray);$i++)
{
	//store the value in the array in a temporary variable to call other functions
	$uidStore = $uidArray[$i];
	printPhoto($uidStore);
	printName($uidStore);
	printRole($uidStore);
	printOrganisation($uidStore);
	printEmail($uidStore);
	printTelephone($uidStore);
}

	//a function to print the user's photo
	function printPhoto($uidStore)
	{
		//print 'Got to printPhoto function! $uidStore = ' . $uidStore . '<br />';
		$photoResult = db_query("SELECT picture FROM users WHERE users.uid = $uidStore");
  

   		while ($photo = db_fetch_object($photoResult)) {

			print '<tr><td valign="top"><a href="user/' . $uidStore . '"><img src="' . $photo->picture . '" width="50px"></a></td>';

		}//end while statement
	}
	
	function printName($uidStore)
	{
		//print 'Got to printName function! $uidStore = ' . $uidStore . '<br />';
		$nameResult = db_query("SELECT name FROM users WHERE users.uid = $uidStore");
  

   		while ($nameRes = db_fetch_object($nameResult)) {

			print '<td valign="top"><p><a href="user/' . $uidStore . '">' . $nameRes->name . '</a></p></td>';

		}//end while statement
	}
	
	function printRole($uidStore)
	{
		//print 'Got to printName function! $uidStore = ' . $uidStore . '<br />';
		$roleResult = db_query("SELECT name FROM role WHERE role.rid = '15'");
  

   		while ($roleRes = db_fetch_object($roleResult)) {

			print '<td valign="top"><p>' . $roleRes->name . '</p></td>';

		}//end while statement
	}
	
	//print organisation
	function printOrganisation($uidStore)
	{
		//print 'Got to printName function! $uidStore = ' . $uidStore . '<br />';
		$orgResult = db_query("SELECT value FROM profile_values WHERE profile_values.fid = '12' AND profile_values.uid = $uidStore");
  
       //check to see if variable is empty
	   //if (isset($orgResult))
	   //{
			while ($orgRes = db_fetch_object($orgResult)) {
	
				print '<td valign="top">' . $orgRes->value . '</td>';
	
			}//end while statement
		//}
        //else
		//{
			//print '<td>Not available</td>';
		//}

	
	}
	
	function printEmail($uidStore)
	{
			//print 'Got to printName function! $uidStore = ' . $uidStore . '<br />';
		$emailResult = db_query("SELECT mail FROM users WHERE users.uid = $uidStore");
  

   		while ($email = db_fetch_object($emailResult)) {

			print '<td valign="top"><p>' . $email->mail . '</p></td>';

		}//end while statement
	}
	function printTelephone($uidStore)
	{
			//print 'Got to printName function! $uidStore = ' . $uidStore . '<br />';
		$phoneResult = db_query("SELECT value FROM profile_values WHERE profile_values.fid = '10' AND profile_values.uid = $uidStore");
  

   		while ($phone = db_fetch_object($phoneResult)) {

			print '<td valign="top">' . $phone->value . '</td></tr>';

		}//end while statement
	}

print '</table>';

Please help!!! :(

scarer’s picture

//print organisation
	function printOrganisation($uidStore)
	{
		//print 'Got to printName function! $uidStore = ' . $uidStore . '<br />';
		$orgResult = db_query("SELECT value FROM profile_values WHERE profile_values.fid = '12' AND profile_values.uid = $uidStore");
  
       //check to see if variable is empty
	   if (isset($orgResult) || empty($orgResult) || is_null($orgResult) || $orgResult == '')
	   {
			while ($orgRes = db_fetch_object($orgResult)) {
			
			   if (empty($orgRes) || is_null($orgRes) || $orgRes == '') 
	   			{ 
	   				print '<td valign="top">Not available</td>';
	   			}
	   			else
	   			{
					print '<td valign="top">' . $orgRes->value . '</td>';
	
				}
			}//end while statement
		}
        else
		{
			print '<td valign="top">Not available</td>';
		}

	
	}
scarer’s picture

Gosh I'm silly. Should have referenced the ARRAY element to test. Works now.

scarer’s picture

actually now it doesn't work.. it just print not available for everything

scarer’s picture

ended up just printing the td tags before and after the while loop