News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Retrieving Custom Profile Field Data

Started by virus52, September 22, 2009, 08:48:41 AM

Previous topic - Next topic

Arantor

Well, first up, if you're inside SMF, should be using $smcFunc in 2.0, and never using mysql_fetch_array.

It would look something like the untested code below.

$list_of_fields = array('cust_ign', 'cust_coords1', 'cust_coords2', 'cust_resourc');

$data = array();

$query = $smcFunc['db_query']('', '
SELECT id_member, member_name FROM {db_prefix}members');

while ($row = $smcFunc['db_fetch_assoc']($query))
{
$data[$row['id_member']] = $row;
foreach ($list_of_fields as $field) // set up blanks for the fields we want in case they're empty
$data[$field] = '';
}

$smcFunc['db_free_result']($query);

$query = $smcFunc['db_query']('', '
SELECT id_member, variable, value FROM {db_prefix}themes
WHERE variable IN ({array_string:fields}) AND id_theme = 1
', array(
'fields' => $list_of_fields,
)
);

while ($row = $smcFunc['db_fetch_assoc']($query))
{
$data[$row['id_member']][$row['variable']] = $row['value'];
}

$smcFunc['db_free_result']($query);

foreach ($data as $row)
{
echo '
<tr>
<td>', $row['member_name'], '</td>';

foreach ($list_of_fields as $field)
echo '
<td>', $row[$field], '</td>';

echo '
</tr>';
}

amuir

Many thanks, Arantor!  I haven't done much with SMF, so I wasn't aware of many of the functions available.  I will look more into $smfFunc as I develop more SSI-based scripts.  The code you posted below worked without error, and I was able to tweak it the little bit needed to restrict it to the Validated membergroup. My members are very happy with the results, and I couldn't have done it without your assistance. Kudos!

Arantor


Advertisement: