I'm looking at some of Jeffrey Randall's code for his Random Profile Module (see below). I understand everything down to...
foreach($usernames as $username)
...which has me stumped. I understand that the username is held in the __users table, not in the __comprofile table, so a query to the users table is necessary to extract the username.
However, user ids are unique, so I don't understand the statement foreach($usernames as $username). Presumably, $usernames refers to a collection of records, but there's only one record per user...yes? SO why have this statement at all?
Roger
$query = "SELECT user_id,avatar FROM #__comprofiler WHERE avatarapproved=1 AND avatar NOT LIKE 'NULL' AND banned='0' ORDER BY RAND() LIMIT $number";
$database ->setQuery ($query);
$results = $database->loadObjectList();
foreach($results as $result){
if(preg_match('/(gallery)/',$result->avatar)){
$query_name = "SELECT id,username FROM #__users WHERE id = ".$result->user_id;
$database ->setQuery ($query_name);
$usernames = $database->loadObjectList();
foreach($usernames as $username){
$profileName = $link_gallery.$result->avatar."\"border=\"0\" alt=\"member image\"$setwidth$setheight/>\n<br/>$username->username</a>$MeMambo\n";
$profile .= "$MamboMe<a href=\"index.php?option=com_comprofiler&task=userProfile&user=".$result->user_id."\">$profileName";
}
Post edited by: Raj, at: 2006/05/19 03:01