WebsiteBaker Logo
  • *
  • Templates
  • Help
  • Add-ons
  • Download
  • Home
*
Welcome, Guest. Please login or register.

Login with username, password and session length
 

News


WebsiteBaker 2.13.6 is now available!


Will it continue with WB? It goes on! | Geht es mit WB weiter? Es geht weiter!
https://forum.websitebaker.org/index.php/topic,32340.msg226702.html#msg226702


The forum email address board@websitebaker.org is working again
https://forum.websitebaker.org/index.php/topic,32358.0.html


R.I.P Dietmar (luisehahne) and thank you for all your valuable work for WB
https://forum.websitebaker.org/index.php/topic,32355.0.html


* Support WebsiteBaker

Your donations will help to:

  • Pay for our dedicated server
  • Pay for domain registration
  • and much more!

You can donate by clicking on the button below.


  • Home
  • Help
  • Search
  • Login
  • Register

  • WebsiteBaker Community Forum »
  • WebsiteBaker Support (2.8.x) »
  • Droplets & Snippets »
  • Request - Users list in frontend
  • Print
Pages: [1]   Go Down

Author Topic: Request - Users list in frontend  (Read 8309 times)

Offline Taajuus

  • Posts: 39
Request - Users list in frontend
« on: April 03, 2010, 08:50:57 AM »
I have a code request, that I think is quite simple to create for those who are more into WB code than me.

I want to have frontend page that shows list of all users that have created user account to my WB site. Simple vertical list with user names.

Also, under each user name I would like to display image. This image link would be in form of http//www.exampleurl.com/username.png. "Username" should be replaced with users login name, for each user.

Help, please! :)
Logged

Offline JC

  • Posts: 55
  • Gender: Male
Re: Request - Users list in frontend
« Reply #1 on: April 03, 2010, 11:37:21 AM »
Hi Taajuus

I'm no programmer but here is some code to get you started. Of course you have to change group_id to which group you want to display.


Code: [Select]
// gets information from table
$result = mysql_query("SELECT * FROM ".TABLE_PREFIX."users WHERE group_id=7 ORDER BY user_id ASC") or die(mysql_error());


echo "<table border='1' bordercolor='#cccccc' cellspacing='0' cellpadding='3'>";
echo "<tr bgcolor='#cccccc'>
         <td>ID</td><td>Name</td><td>Username</td><td>E-mail</td></tr>";


// gets results from table
while($row = mysql_fetch_array( $result ))

{
     // prints content row by row
echo "<tr><td>";   
echo $row['user_id'];
echo "</td><td>";     
      echo "<b>"; 
echo $row['display_name'];
      echo "</b>";
echo "</td><td>";
echo $row['username'];
echo "</td><td>";
      echo "<b>";
echo $row['email'];
      echo "</b>";
echo "</td></tr>";
   
}

echo "</table>";

I hope it can be of any help!

/JC
Logged

Offline pcwacht

  • Posts: 2923
  • Gender: Male
    • Dutch ICT info
Re: Request - Users list in frontend
« Reply #2 on: April 03, 2010, 11:43:42 AM »
made a droplet for eliteforcemars.nl a while ago
Code: [Select]
global $database, $wb;
$return = " ";
$query = "SELECT * FROM ".TABLE_PREFIX."users WHERE display_name<>'Admin' ORDER BY group_id";
$result = $database->query($query);

$return .= "<ul>";
while($row = $result->fetchRow())   {
          $return .= "<li>".$row["display_name"]."</li>";
#          $return .= "<br>";
     }
$return .= "</ul>";
return $return;


Create some image there.

Have fun,
John
Logged
http://www.ictwacht.nl = Dutch ICT info
http://www.pcwacht.nl = My first
both still work in progress, since years.....

Offline Taajuus

  • Posts: 39
Re: Request - Users list in frontend
« Reply #3 on: April 03, 2010, 12:25:26 PM »
Quote from: pcwacht on April 03, 2010, 11:43:42 AM
made a droplet for eliteforcemars.nl a while ago
[

This seems to work nice as droplet, thanks!

But small problem still. This code gives output as text to image url I want, but how do i change it so it shows it as image, rather than text output?

Code: [Select]
global $database, $wb;
$return = " ";
$query = "SELECT * FROM ".TABLE_PREFIX."users WHERE display_name<>'Admin' ORDER BY group_id";
$result = $database->query($query);

$return .= "";
while($row = $result->fetchRow())   {
          $return .= "http://bfbc2.statsverse.com/sig/detail1/ps3/".$row["display_name"].".png"."<br>";
#          $return .= "<br>";
     }
$return .= "";
return $return;

I tried this, but something wrong with my php coding :D

Code: [Select]
global $database, $wb;
$return = " ";
$query = "SELECT * FROM ".TABLE_PREFIX."users WHERE display_name<>'Admin' ORDER BY group_id";
$result = $database->query($query);

$return .= "";
while($row = $result->fetchRow())   {
          $return .= "<img src="http://bfbc2.statsverse.com/sig/detail1/ps3/".$row["display_name"].".png">"."<br>";
#          $return .= "<br>";
     }
$return .= "";
return $return;
Logged

aldus

  • Guest
Re: Request - Users list in frontend
« Reply #4 on: April 03, 2010, 12:54:17 PM »
hm ...

Some typos and incorrect use of quotes ... that's all
Code: [Select]
<?php // not this line ;-)
global $database, $wb;

$return = " ";

$query = "SELECT * FROM `".TABLE_PREFIX."users` WHERE `display_name`<>&#39;Admin&#39; ORDER BY group_id";
$result = $database->query($query);

while( 
true == ($row = $result->fetchRow())) {
$return .= "<img src=\"http://bfbc2.statsverse.com/sig/detail1/ps3/".$row["display_name"].".png\" alt=&#39;&#39; /><br />";
} 
return 
$return;


Regards
Aldus
Logged

Offline Taajuus

  • Posts: 39
Re: Request - Users list in frontend
« Reply #5 on: April 03, 2010, 07:52:01 PM »
Ok, I need some more help  :-D This is more php related... Since I'm not expert.

Now I have script that pulls out WB users from database, something like this:

Code: [Select]
// gets information from table
$result = mysql_query("SELECT * FROM ".TABLE_PREFIX."users WHERE group_id=7 ORDER BY user_id ASC") or die(mysql_error());

// gets results from table
while($row = mysql_fetch_array( $result ))

echo $row['username'];

Then I have another script, that wants variable of usernames like this:

Code: [Select]
//prep the members
$members = "user1,user2,user3";

How could I combine so that usernames first code pulls out from database would be inserted to this other scripts as $members data? Since this other script is designed so you insert $members data manually (comma separated), but I want it to use usernames straight from WB database automaticly...

I can show whole script, if needed.
Logged

Offline Taajuus

  • Posts: 39
Re: Request - Users list in frontend
« Reply #6 on: April 04, 2010, 11:18:06 AM »
Ok, heres the full code.
 
How should I modify this, so that instead of  $members = "user1,user2,user3"; I could pull out these users (comma separated) from WB database?

Please help, this is the last piece of puzzle for my site :)

Code: [Select]
<?php


//prep the members

// The most important piece.  Add all your friends separated by commas.
$members = "user1,user2,user3";



$rankpoints=array(
1 => 0,
2 => 11000,
3 => 18500,
4 => 28000,
5 => 40000,
6 => 53000,
7 => 68000,
8 => 84000,
9 => 100000,
10 => 120000,
11 => 138000,
12 => 158000,
13 => 179000,
14 => 200000,
15 => 224000,
16 => 247000,
17 => 272000,
18 => 297000,
19 => 323000,
20 => 350000,
21 => 377000,
22 => 405000,
23 => 437000,
24 => 472000,
25 => 537000,
26 => 620000,
27 => 720000,
28 => 832000,
29 => 956000,
30 => 1092000,
31 => 1240000,
32 => 1400000,
33 => 1572000,
34 => 1756000,
35 => 1952000,
36 => 2160000,
37 => 2380000,
38 => 2612000,
39 => 2856000,
40 => 3112000,
41 => 3380000,
42 => 3660000,
43 => 3952000,
44 => 4256000,
45 => 4572000,
46 => 4900000,
47 => 5240000,
48 => 5592000,
49 => 5956000,
50 => 6332000); 

//grab the stats!
$url = &#39;http://api.bfbcs.com/api/ps3&#39;;
$postdata = &#39;players=&#39;.$members.&#39;&fields=general&#39;;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
$data = curl_exec($ch);
curl_close($ch);
$data = json_decode($data,true);

if(isset(
$_GET[&#39;debug&#39;]))
{
var_dump($data);
echo &#39;<br /><br />&#39;;
}
//loop through the data and store stats in an array
$stats = array();

for(
$x=0;$x<count($data[&#39;players&#39;]);$x++)
{
$name = $data[&#39;players&#39;][$x][&#39;name&#39;];
$rank = $data[&#39;players&#39;][$x][&#39;rank&#39;];
$score = $data[&#39;players&#39;][$x][&#39;score&#39;];
$kills = $data[&#39;players&#39;][$x][&#39;kills&#39;];
$deaths = $data[&#39;players&#39;][$x][&#39;deaths&#39;];
$raw_time = sec2hms($data[&#39;players&#39;][$x][&#39;time&#39;]);

$ratio = number_format($kills/$deaths, 2, &#39;.&#39;, &#39;&#39;);

$dogtags = $data[&#39;players&#39;][$x][&#39;general&#39;][&#39;dogt&#39;];
$total_time=$data[&#39;players&#39;][$x][&#39;time&#39;];
$SPM=number_format($score/($total_time/60), 2, &#39;.&#39;, &#39;&#39;);
$KPM=number_format($kills/($total_time/60), 2, &#39;.&#39;, &#39;&#39;);
$DPM=number_format($deaths/($total_time/60), 2, &#39;.&#39;, &#39;&#39;);

$score_general = $data[&#39;players&#39;][$x][&#39;general&#39;][&#39;sc_general&#39;];
$score_award = $data[&#39;players&#39;][$x][&#39;general&#39;][&#39;sc_award&#39;];
$score_bonus = $data[&#39;players&#39;][$x][&#39;general&#39;][&#39;sc_bonus&#39;];
$score_team = $data[&#39;players&#39;][$x][&#39;general&#39;][&#39;sc_team&#39;];
$score_squad = $data[&#39;players&#39;][$x][&#39;general&#39;][&#39;sc_squad&#39;];

//calculate which class they use
$assault = $data[&#39;players&#39;][$x][&#39;general&#39;][&#39;sc_assault&#39;];
$recon = $data[&#39;players&#39;][$x][&#39;general&#39;][&#39;sc_recon&#39;];
$demo = $data[&#39;players&#39;][$x][&#39;general&#39;][&#39;sc_demo&#39;];
$support = $data[&#39;players&#39;][$x][&#39;general&#39;][&#39;sc_support&#39;];

$the_classes = array();
$the_classes[0] = array(&#39;name&#39;=>&#39;assault&#39;,&#39;score&#39;=>$assault);
$the_classes[1] = array(&#39;name&#39;=>&#39;recon&#39;,&#39;score&#39;=>$recon);
$the_classes[2] = array(&#39;name&#39;=>&#39;demo&#39;,&#39;score&#39;=>$demo);
$the_classes[3] = array(&#39;name&#39;=>&#39;support&#39;,&#39;score&#39;=>$support);

//sort the classes array by score
usort($the_classes,&#39;compare_stats&#39;);

$most_used = $the_classes[0][&#39;name&#39;];

$NextRank=intval($rank+1);

// Search next rank
if( empty($NextRank) )
$nextRankID = $rank;
else {
if($rankpoints[$rank] == $rankpoints[($rank + 1)])
{
$nextRankID = 0;
for ($m=($rank + 1);$m<(count($rankpoints)-1);$m++)
{
if( ($rankpoints[$m] > $rankpoints[$rank]) && ($nextRankID == 0) ) $nextRankID = $m;
}
}
else $nextRankID = ($rank + 1);
    }

if($rank < 10) { $rank = "0".$rank; }

$stats[$x] = array(&#39;name&#39;=>$name,&#39;rank&#39;=>$rank,&#39;score&#39;=>$score,&#39;kills&#39;=>$kills,&#39;deaths&#39;=>$deaths,&#39;ratio&#39;=>$ratio,&#39;time&#39;=>$raw_time,&#39;most_used&#39;=>$most_used,&#39;dogtags&#39;=>$dogtags,&#39;SPM&#39;=>$SPM,&#39;KPM&#39;=>$KPM,&#39;DPM&#39;=>$DPM,&#39;sc_general&#39;=>$score_general,&#39;sc_award&#39;=>$score_award,&#39;sc_bonus&#39;=>$score_bonus,&#39;sc_team&#39;=>$score_team,&#39;sc_squad&#39;=>$score_squad,&#39;score_rank&#39;=> $score - $rankpoints[$nextRankID-1],&#39;diff_score&#39;=> $rankpoints[$nextRankID] - $rankpoints[$nextRankID-1],&#39;nextrankid&#39;=> $nextRankID,&#39;nextrankscore&#39; => $rankpoints[$nextRankID]);

}

function 
sec2hms ($sec, $padHours = false) 
{
$hms = "";
$hours = intval(intval($sec) / 3600); 
$hms .= ($padHours) 
  ? str_pad($hours, 2, "0", STR_PAD_LEFT). &#39;:&#39;
  : $hours. &#39;h &#39;; 
$minutes = intval(($sec / 60) % 60); 
$hms .= str_pad($minutes, 2, "0", STR_PAD_LEFT). &#39;m &#39;;
$seconds = intval($sec % 60); 
$hms .= str_pad($seconds, 2, "0", STR_PAD_LEFT).&#39;s&#39;;
return $hms;
}


function 
compare_stats($x,$y)
{
if($x[&#39;score&#39;] == $y[&#39;score&#39;])
{
return 0;
}
elseif($x[&#39;score&#39;] < $y[&#39;score&#39;])
{
return 1;
}
else
{
return -1;
}
}

//sort the stats array by score
usort($stats,&#39;compare_stats&#39;);


?>


<div align="center">
<table border="0" width="100%" id="table1">

<tr>
<td align="center">&nbsp;</td>

<td><b>Player</b></td>

<td align="center"><b>Kills</b></td>
<td align="center"><b>Deaths</b></td>
<td align="center"><b>KDR</b></td>
<td align="center"><b>Total Time</b></td>
</tr>

    <?php
for(
$out=0;$out<count($stats);$out++)
{
$pos = $out + 1;
?>


<tr><td width="29" align="center"><img src="http://battlefieldbadcompany2.com/files/gui/img/stats/ranks/tiny/R0<?php echo &#39;&#39;.$stats[$out][&#39;rank&#39;].&#39;&#39; ?>.png" alt="<?php echo &#39;&#39;.$stats[$out][&#39;rank&#39;].&#39;&#39; ?>" /></td>



<td><a href="http://bfbcs.com/stats_ps3/<?php echo &#39;&#39;.$stats[$out][&#39;name&#39;].&#39;&#39; ?>" target="_blank"><?php echo &#39;&#39;.$stats[$out][&#39;name&#39;].&#39;&#39; ?></a></td>






<td align="center"><?php echo &#39;&#39;.$stats[$out][&#39;kills&#39;].&#39;&#39; ?></td>
<td align="center"><?php echo &#39;&#39;.$stats[$out][&#39;deaths&#39;].&#39;&#39; ?></td>
<td align="center"><?php echo &#39;&#39;.$stats[$out][&#39;ratio&#39;].&#39;&#39; ?></td>
<td align="center"><?php echo &#39;&#39;.$stats[$out][&#39;time&#39;].&#39;&#39; ?></td>
</tr>
    <?php
}

?>

</table>
</div>

<?php
if(!empty($data[&#39;players_nodata&#39;]))
{
echo &#39;<br><div align="center" id="stats_waiting">&#39;.count($data[&#39;players_nodata&#39;]).&#39; playerststs waiting in que.</div>&#39;;
}
?>

<br>
<div align="center">Stats updated every six hours.</div>

<br>
<p align="center">Powered by: <a target="_blank" href="http://bfbcs.com/ps3">bfbcs.com</a></p>

Logged

Offline Taajuus

  • Posts: 39
Re: Request - Users list in frontend
« Reply #7 on: April 07, 2010, 08:27:51 AM »
Anyone? Please :?
Logged

Offline pcwacht

  • Posts: 2923
  • Gender: Male
    • Dutch ICT info
Re: Request - Users list in frontend
« Reply #8 on: April 07, 2010, 09:33:06 AM »
combine the two

To get comma separated users:

$members = '';
$query = "SELECT * FROM `".TABLE_PREFIX."users` WHERE `display_name`<>'Admin' ORDER BY group_id";
$result = $database->query($query);

while( true == ($row = $result->fetchRow())) {
   $members .= $row["display_name"].",";
}


Past your other code here..

Have fun,
John
Logged
http://www.ictwacht.nl = Dutch ICT info
http://www.pcwacht.nl = My first
both still work in progress, since years.....

Offline Taajuus

  • Posts: 39
Re: Request - Users list in frontend
« Reply #9 on: April 07, 2010, 07:30:53 PM »
Works like a charm! THANKS! :-D
Logged

  • Print
Pages: [1]   Go Up
  • WebsiteBaker Community Forum »
  • WebsiteBaker Support (2.8.x) »
  • Droplets & Snippets »
  • Request - Users list in frontend
 

  • SMF 2.0.19 | SMF © 2017, Simple Machines
  • XHTML
  • RSS
  • WAP2