Jump to the post that solved this thread.
Solved: 1 Year ago Use simple_select to get custom profile fields
#3
Solved: 1 Year ago
(2020-09-22, 01:49 PM)Crazycat Wrote: Well, first I don't think using "IN" clause to get an unique value is optimal.
And this is the case you'd better use write_query than simple_select to extract your datas:
$query = $db->write_query("SELECT u.*, f.fid4 FROM ".TABLE_PREFIX."users u LEFT JOIN ".TABLE_PREFIX."userfields f ON f.ufid=u.uid WHERE u.usergroup=18 ORDER BY u.username ASC");
while($users = $db->fetch_array($query))
{
   $username = build_profile_link(format_name(htmlspecialchars_uni($users['username']), $users['usergroup'], $users['displaygroup']), $users['uid']);
   $ufield = '';
   if ($users['fid4']=='')
   {
      $ufield = '<br />'.$users['fid4'];
   }
   $userlist .= '<tr><td class="'.$altbg.'">'.$username.', '.$users["usertitle"].'<br />'.$ufield.'</td></tr>';
   $altbg = alt_trow();
 }

Thank you very much.
Your code didn't show user fields though (although they are filled).
I deleted the if and it works now, here is the final code:

<?php

global $headerinclude, $header, $theme, $footer, $db, $xtpf, $userfields;

$altbg = alt_trow();

$query = $db->write_query("SELECT u.*, f.fid4 FROM ".TABLE_PREFIX."users u LEFT JOIN ".TABLE_PREFIX."userfields f ON f.ufid=u.uid WHERE u.usergroup=18 ORDER BY u.username ASC");
while($users = $db->fetch_array($query))
{
   $username = build_profile_link(format_name(htmlspecialchars_uni($users['username']), $users['usergroup'], $users['displaygroup']), $users['uid']);

      $ufield = $users['fid4'];
  
   $userlist .= '<tr><td class="'.$altbg.'">'.$username.', '.$users["usertitle"].' '.$ufield.'</td></tr>';
   $altbg = alt_trow();
 }











$template='<html>
<head>
<title>'.$pages['name'].'</title>
{$headerinclude}
</head>
<body>
{$header}
<table border="0" cellspacing="'.$theme['borderwidth'].'" cellpadding="'.$theme['tablespace'].'" class="tborder">
<thead>
<tr>
<td class="thead">
<strong>'.$pages['name'].'</strong>
</td>
</tr>
</thead>
<tbody>
{$userlist}
</tbody>
</table>
<br />
{$footer}
</body>
</html>';

$template=str_replace("\'", "'", addslashes($template));

add_breadcrumb($pages['name']);

eval("\$page=\"".$template."\";");

output_page($page);

?>

Would this cause a problem when the field is empty? (for the case of fid4, it is required but what about other fields?)
Reply
Jump to the post that solved this thread.


Messages In This Thread
RE: Use simple_select to get custom profile fields - by volkling - 2020-09-22, 03:39 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)