Request - Users list in frontend

Taajuus


pcwacht

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
[url="http://www.ictwacht.nl"]http://www.ictwacht.nl[/url] = Dutch ICT info
[url="http://www.pcwacht.nl"]http://www.pcwacht.nl[/url] = My first
both still work in progress, since years.....


Taajuus

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 :)


<?php


//prep the members

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



$rankpoints=array(
=> 0,
=> 11000,
=> 18500,
=> 28000,
=> 40000,
=> 53000,
=> 68000,
=> 84000,
=> 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 'http://api.bfbcs.com/api/ps3';
$postdata 'players='.$members.'&fields=general';
$ch curl_init($url);
curl_setopt($chCURLOPT_POSTtrue);
curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
curl_setopt($chCURLOPT_POSTFIELDS$postdata);
$data curl_exec($ch);
curl_close($ch);
$data json_decode($data,true);

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

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

$ratio number_format($kills/$deaths2'.''');

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

$score_general $data['players'][$x]['general']['sc_general'];
$score_award $data['players'][$x]['general']['sc_award'];
$score_bonus $data['players'][$x]['general']['sc_bonus'];
$score_team $data['players'][$x]['general']['sc_team'];
$score_squad $data['players'][$x]['general']['sc_squad'];

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

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

//sort the classes array by score
usort($the_classes,'compare_stats');

$most_used $the_classes[0]['name'];

$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('name'=>$name,'rank'=>$rank,'score'=>$score,'kills'=>$kills,'deaths'=>$deaths,'ratio'=>$ratio,'time'=>$raw_time,'most_used'=>$most_used,'dogtags'=>$dogtags,'SPM'=>$SPM,'KPM'=>$KPM,'DPM'=>$DPM,'sc_general'=>$score_general,'sc_award'=>$score_award,'sc_bonus'=>$score_bonus,'sc_team'=>$score_team,'sc_squad'=>$score_squad,'score_rank'=> $score $rankpoints[$nextRankID-1],'diff_score'=> $rankpoints[$nextRankID] - $rankpoints[$nextRankID-1],'nextrankid'=> $nextRankID,'nextrankscore' => $rankpoints[$nextRankID]);

}

function 
sec2hms ($sec$padHours false
{
$hms "";
$hours intval(intval($sec) / 3600); 
$hms .= ($padHours
  ? str_pad($hours2"0"STR_PAD_LEFT). ':'
  : $hours'h '
$minutes intval(($sec 60) % 60); 
$hms .= str_pad($minutes2"0"STR_PAD_LEFT). 'm ';
$seconds intval($sec 60); 
$hms .= str_pad($seconds2"0"STR_PAD_LEFT).'s';
return $hms;
}


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

//sort the stats array by score
usort($stats,'compare_stats');


?>


<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 ''.$stats[$out]['rank'].'' ?>.png" alt="<?php echo ''.$stats[$out]['rank'].'' ?>" /></td>



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






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

?>

</table>
</div>

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

<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>


Taajuus

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:

// 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:

//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.

aldus

hm ...

Some typos and incorrect use of quotes ... that's all

<?php // not this line ;-)
global $database$wb;

$return " ";

$query "SELECT * FROM `".TABLE_PREFIX."users` WHERE `display_name`<>'Admin' 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='' /><br />";

return 
$return;



Regards
Aldus

Taajuus

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?

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

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;

pcwacht

made a droplet for eliteforcemars.nl a while ago

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
[url="http://www.ictwacht.nl"]http://www.ictwacht.nl[/url] = Dutch ICT info
[url="http://www.pcwacht.nl"]http://www.pcwacht.nl[/url] = My first
both still work in progress, since years.....

JC

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.


// 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

Taajuus

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! :)