Home
Download
Add-ons
Help
Forum
Organisation
Project
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
May 26, 2012, 10:42:13 AM
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Search:
Advanced search
Interested in joining the WebsiteBaker team?
For more Information read
here
or on our
new website
.
155538
Posts in
21715
Topics by
7737
Members
Latest Member:
chris85
WebsiteBaker Community Forum
English
Droplets (PHP code for use with Droplet module) & Snippets (raw PHP code)
(Moderator:
Argos
)
Request - Users list in frontend
Pages: [
1
]
Go Down
Author
Topic: Request - Users list in frontend (Read 873 times)
Taajuus
Offline
Posts: 37
Request - Users list in frontend
«
on:
April 03, 2010, 07: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
JC
Offline
Posts: 56
Re: Request - Users list in frontend
«
Reply #1 on:
April 03, 2010, 10: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:
// 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
pcwacht
AddOn Development
Offline
Posts: 2859
Re: Request - Users list in frontend
«
Reply #2 on:
April 03, 2010, 10:43:42 AM »
made a droplet for eliteforcemars.nl a while ago
Code:
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.....
Taajuus
Offline
Posts: 37
Re: Request - Users list in frontend
«
Reply #3 on:
April 03, 2010, 11:25:26 AM »
Quote from: pcwacht on April 03, 2010, 10: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:
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
Code:
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
Offline
Posts: 1238
Re: Request - Users list in frontend
«
Reply #4 on:
April 03, 2010, 11:54:17 AM »
hm ...
Some typos and incorrect use of quotes ... that's all
Code:
<?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
Logged
Taajuus
Offline
Posts: 37
Re: Request - Users list in frontend
«
Reply #5 on:
April 03, 2010, 06:52:01 PM »
Ok, I need some more help
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:
// 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:
//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
Taajuus
Offline
Posts: 37
Re: Request - Users list in frontend
«
Reply #6 on:
April 04, 2010, 10: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:
<?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
=
'http://api.bfbcs.com/api/ps3'
;
$postdata
=
'players='
.
$members
.
'&fields=general'
;
$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
[
'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
/
$deaths
,
2
,
'.'
,
''
);
$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
(
$hours
,
2
,
"0"
,
STR_PAD_LEFT
).
':'
:
$hours
.
'h '
;
$minutes
=
intval
((
$sec
/
60
) %
60
);
$hms
.=
str_pad
(
$minutes
,
2
,
"0"
,
STR_PAD_LEFT
).
'm '
;
$seconds
=
intval
(
$sec
%
60
);
$hms
.=
str_pad
(
$seconds
,
2
,
"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"> </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>
Logged
Taajuus
Offline
Posts: 37
Re: Request - Users list in frontend
«
Reply #7 on:
April 07, 2010, 07:27:51 AM »
Anyone? Please
Logged
pcwacht
AddOn Development
Offline
Posts: 2859
Re: Request - Users list in frontend
«
Reply #8 on:
April 07, 2010, 08: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.....
Taajuus
Offline
Posts: 37
Re: Request - Users list in frontend
«
Reply #9 on:
April 07, 2010, 06:30:53 PM »
Works like a charm! THANKS!
Logged
Pages: [
1
]
Go Up
Jump to:
Please select a destination:
-----------------------------
General
-----------------------------
=> General Announcements
=> Security Announcements
=> Documentation
=> WebsiteBaker Website Showcase
=> Guest Area & Off-Topic
-----------------------------
English
-----------------------------
=> WebsiteBaker 2.9
===> Announcements
===> Help/Support
=====> Modules / Extensions
===> Suggestions
===> Software bugs
=> Help & Support
=> Modules
=> Droplets (PHP code for use with Droplet module) & Snippets (raw PHP code)
=> jQuery
=> Templates, Menus & Design
=> WebsiteBaker Language Files
=> WebsiteBaker 2.x discussion
=> WebsiteBaker 3
=> Archive (posts up to 2007)
-----------------------------
Deutsch (German)
-----------------------------
=> Ankündigungen
=> WebsiteBaker 2.9
===> Ankündigungen
===> Hilfe/Support
=====> Module / Extensions
===> Vorschläge
===> Softwarefehler
===> Erfahrungs und Testberichte
=> Hilfe/Support
=> Module & Snippets
=> Templates & Design
=> Tutorials
=> jQuery
=> Diskussion über WB
=> Off-Topic
=> Archiv für Themen bis 2007
-----------------------------
Nederlands (Dutch)
-----------------------------
=> Aankondigingen
=> Hulp & Ondersteuning
=> Niet-Terzake (Off Topic)
-----------------------------
Francais (French)
-----------------------------
=> Help/Support
-----------------------------
Italiano (Italian)
-----------------------------
=> Help/Support
-----------------------------
Bakery (WB shop module)
-----------------------------
=> Bakery English
=> Bakery Deutsch
-----------------------------
KeepInTouch (Multi Contact Module)
-----------------------------
=> KeepInTouch English
=> KeepInTouch Deutsch
Loading...