Quantcast
Channel: phpBB.com
Viewing all articles
Browse latest Browse all 393

phpBB Custom Coding • External PHP code to view all custom profile fields

$
0
0
I have put together some php code to enable you to view all of the phpbb3 custom profile fields in a table.
Unlike the memberlist each custom field is displayed in a seperate column of the table and can easily be sorted.
The list can be sorted by the first letter of the username, by the userid either ascending or descending and can be sorted alphabetically on any of the other fields.
The attached files contain an example of the table header and instructions on how to use the code.
I hope the code may be useful to you
Dave

Code:

    <html><title>Display All Members and Custom Profiles</title>    <head><link href="styles/webform.css" rel="stylesheet" type="text/css"><style><!-- body, td, th { font-family: Tahoma, Geneva, sans-serif;}--></style></head><?phpinclude 'config.php';$dbhost = "localhost";//-------------------------------------------------// Modify this session to your requirements//-------------------------------------------------//-------------------------------------------------// Custom field name prefix//// ALL Custom field name MUST have this prefix//-------------------------------------------------    $field_prefix = "phpbb_";//-------------------------------------------------// Set Custom Column Order//// See # numbers of field names in structure of // phpbb_profile_fields_data  - starting from #2//-------------------------------------------------// Don't set field1, field2, and field3// All other fields must be included    $field4="5";    $field3="4";    $field5="6";    $field6="8";    $field7="7";    $field8="3";    $field9="2";    //-------------------------------------------------    $conn = mysqli_connect($dbhost, $dbuser, $dbpasswd, $dbname);    // Check connection    if (!$conn) {        die("Connection failed: " . mysqli_connect_error());    }//establishing connection to the database$mysqli = mysqli_connect($dbhost, $dbuser, $dbpasswd, $dbname);if (mysqli_connect_errno()) {  echo "Failed to connect to MySQL: ". mysqli_connect_error();  exit();}//-------------------------------------------------?><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css"><style><!-- body, td, th { font-family: Tahoma, Geneva, sans-serif;}--></style><script>function refresh() {     window.location.reload(); }</script><body text="#000000" link="#006600" vlink="#990000" ><table><div align="left">  <p><span><u>Display All Members and Custom Profiles</u></span></p>  <table width="1550" border="0">               <td width="528" height="26" valign="middle" ><div align="justify"> <?php//-------------------------------------------------// $query_1//-------------------------------------------------$query_1 = "SELECT  * from phpbb_profile_fields_data ORDER BY user_id";//-------------------------------------------------// Sending $query_1 to obtain custom column names//------------------------------------------------- if ($result = $mysqli->query($query_1)) {        /* Get field names for custom columns */        $finfo = $result->fetch_fields();        foreach ($finfo as $val) {                       $column_names = $column_names . ",' phpbb_profile_fields_data." . $val->name . "'";               }           }      $result -> free_result(); $my_array = explode(",",  $column_names);//-------------------------------------------------// Display alphabet//-------------------------------------------------echo "Select Initial of User Name:- &nbsp;&nbsp;&nbsp;";for($i=65; $i<=90; $i=$i+1){echo '<a href="' . $_SERVER['SCRIPT_NAME'] . '?u_letter=&#' . $i . '">&#' . $i . '&nbsp;</a>';} echo '<a href="' . $_SERVER['SCRIPT_NAME'] . '?u_letter=*' . '"> All' . '</a>';$u_letter = trim($_GET['u_letter']);if ($u_letter == ""){$u_letter = "*" ;}setcookie('$u_letter', $u_letter); setcookie('$u_letter', $u_letter); ?>  <!-----------------------------------------------> <!-- Display sort titles                       --> <!----------------------------------------------->  </div></td> </table> <br> <table width="1100" border="0">  <tr>    <td width="1100">Sort full list by:</td>  </tr></table>  <table style="width:1300" border="0">   <tr>          <td style="width:6%"><?php  echo '<a href="' . $_SERVER['SCRIPT_NAME'] . '?u_letter=asc' . '">&#x2B06;' . '</a>';?><?php  echo 'User ID';?><?php  echo '<a href="' . $_SERVER['SCRIPT_NAME'] . '?u_letter=desc' . '">&#x2B07;' . '</a>';?></td>   <td style="width:9%"><?php echo '<a href="' . $_SERVER['SCRIPT_NAME'] . '?u_letter=username' . '">User Name' . '</a>';    ?></td>   <td style="width:8%"><?php echo '<a href="' . $_SERVER['SCRIPT_NAME'] . '?u_letter=user_email' . '">Email' . '</a>';           ?></td>    <?php                                        for ($x =3; $x <= count($my_array); $x++) {                                                                                                          $a = str_replace(array("'", '"'), ' ', $my_array[${"field" . $x}]);                                    $b = str_replace(array("'", 'phpbb_profile_fields_data.pf_phpbb_'), ' ', $my_array[${"field" . $x}]);                                                                        ?>                                                                           <td ><?php echo '<a href="' . $_SERVER['SCRIPT_NAME'] . '?u_letter=' . $a . '">' . $b . ' </a>';           ?></td>                                                                                                           <?php                                    }                                                                        $str = $u_letter;                                                                      $str2 =  str_replace('phpbb_profile_fields_data.pf_' . $field_prefix , ' ',$str);                                                                    ?>   </tr></table>  <br> <!-----------------------------------------------> <?php//-------------------------------------------------// Creating $query_2 to obtain all columns//-------------------------------------------------$mid_query_str = str_replace("'", "", $column_names);$query_2 = "SELECT phpbb_users.user_id, phpbb_users.username, phpbb_users.user_email " . $mid_query_str . " FROM phpbb_users LEFT JOIN phpbb_profile_fields_data ON phpbb_users.user_id = phpbb_profile_fields_data.user_id";$query_2 = str_replace("'", "", $query_2);$query_2 = str_replace(" phpbb_profile_fields_data.user_id, ", "", $query_2);//-------------------------------------------------//Sort by Lastname Initial selected//-------------------------------------------------if ($u_letter == "asc") {        $sql = $query_2 .  "  ORDER BY phpbb_users.user_id ASC";    } elseif ($u_letter == "desc") {         $sql = $query_2 .  "  ORDER BY phpbb_users.user_id DESC";    } elseif ($u_letter == "*") {         $sql =  $query_2 . "  ORDER BY phpbb_users.user_id";    } elseif (  (ctype_alpha($u_letter) == 1)  && (strlen($u_letter) == 1 ) ) {         $sql = $query_2 . " where left(phpbb_users.username,1)='$u_letter'";          } else {             if ($u_letter == "email") {        $sql =  $query_2 . "  ORDER BY phpbb_users.user_email";        }                        if ($u_letter == "username") {        $sql =  $query_2 .  "  ORDER BY phpbb_users.username";        }                 if ($u_letter = $str2) {                   $sql =  $query_2 .  "  ORDER BY " . $str;        }                    if (!$result) {            die("Query to show fields from table failed");        }} //-------------------------------------------------// Display table column names and data//-------------------------------------------------$my_array = explode(",",  $column_names); $result = mysqli_query($mysqli, $sql);    if (mysqli_num_rows($result) > 0)         {     ?>                       <table border='1'>                            <tr bgcolor = '#DDEEAA' >                                      <td width="80">user_id</td>                                    <td width="150">username</td>                                    <td width="260">user_email</td>                                                                         <?php                                        for ($x =3; $x <= count($my_array); $x++) {                                                                               ?>                                                                <td width="240"><?php echo str_replace(array("'", 'phpbb_profile_fields_data.pf_phpbb_'), ' ', $my_array[${"field" . $x}]); ?></td>                                                                    <?php                                    }                                                                       ?>                           </tr>                                      <?php                                          while($row = mysqli_fetch_array($result))                             {                                                    ?>                                <tr>                                   <td width="80"><?php echo $row["user_id"]; ?></td>                                    <td width="150"><?php echo $row["username"]; ?></td>                                    <td width="260"><?php echo $row["user_email"]; ?></td>                                                                    <?php                                                                         for ($x =3; $x <= count($my_array); $x++) {                                                                     ?>                                                                   <td width="240"><?php echo $row[${"field" . $x}+1]; ?></td>                                                                     <?php                                    }                                    ?>                              </tr>                                          <?php                                                            $i++;                            }                                        ?>                        </table>                       <?php                            }                            else{                            echo "No result found";               }mysql_free_result($result);    ?>   
Example table header

Instructions for display_custom_profiles..jpg

Statistics: Posted by dave2565 — Wed Mar 27, 2024 3:45 pm



Viewing all articles
Browse latest Browse all 393

Latest Images

Trending Articles





Latest Images