[PHP] ODBC Top 25 Players for your site
Alright, so I'm new to this forums, and you will find me releasing a lot of web related stuff. I can do software programming but I prefer doing web related things. It catches my interest. Anyways, this is a very simple script for displaying the top 25(configurable) players on your server to your website. Pretty much everything is configurable just edit the $variables accordingly. The default configuration is to display the top 25 players by their XP. I trust that the user(s) will understand how to turn this simple script into tables and whatnot using html. So if you have any question please feel free to ask and enjoy.
Also here is an example of what the code alone displays using my GunZ server's databases:
I only have 5 characters since we just started this server yesterday so that's all that will be displayed for me (and i sorta gave us all a lot of xp for testing items and quests) but:
LexTheGreat with 1000184439XP!
Nikku with 1000170447XP!
DamianDarc with 1000046951XP!
alisterxxx with 1000045455XP!
YennLee with 999999999XP!
ima_rapeyou with 999996519XP!
PHP Code:
<?php
//Created by DamianDarc/Deathtaker26 ~ GHOUL GAMING Private Server Network
//GunZ Top Score System
$host='';
$user='sa';
$pass='Password';
$db='GunzDB';
$chartable='Character';
$OrderByRow='XP';
$display=25;
$con=odbc_connect("Driver={SQL Server};Server=$host;Database=$db;", $user, $pass) or die("We could not connect to the MSSQL Server, please contact the server administrations or try again later.");
$query=odbc_exec($con, 'SELECT top ' . $display . ' * FROM ' . $chartable . ' ORDER BY ' . $OrderByRow . ' DESC');
while ($row = odbc_fetch_array($query)){
echo $row['Name'] . ' with ' . $row[$OrderByRow] . 'XP! <br />';
}
odbc_free_result($query);
?>
Re: [PHP] ODBC Top 25 Players for your site
is not special,
but good for people that still can't use mssql
Re: [PHP] ODBC Top 25 Players for your site
Yeah, I know it's supposed to be simple I like releasing things for people who I know can't do much. I'll be sure to release and awesome fully configurable GunZ site when I'm all done.
Thank you for the feedback!
Re: [PHP] ODBC Top 25 Players for your site
Tips:
- Only select the columns you need, don't use *. (Query will be faster.)
- odbc_free_result is not really necessary.
- There's no need to store the character table, xp column name and the amount of rows in variables.
Re: [PHP] ODBC Top 25 Players for your site
Thank you for the advice. I just like making things more configurable, like I said it's for people who can't really use mssql or php. I'll be sure to follow your advice in the future.
Oh and the reason I used * was because I was also adding a few rows to it as well. The version I'm using is a bit different.
Re: [PHP] ODBC Top 25 Players for your site
Code:
$query = odbc_exec("SELECT TOP 25 Name, XP FROM Character WHERE DeleteFlag='0'");
$i = 1;
while($f = odbc_fetch_array($query)){
echo $i.' - '.$f['name'].' has '.$f['XP'].' amount of xp';
$i++
}
isn't this much simpler?
Re: [PHP] ODBC Top 25 Players for your site
Not if you want it to be more configurable, plus I'm not trying to offend you or anything but it actually looks sloppy.
Re: [PHP] ODBC Top 25 Players for your site
jur13n's method is a lot simpler. Judging by the php coding you did is actually more sloppy.
Re: [PHP] ODBC Top 25 Players for your site
Quote:
Originally Posted by
Anju
jur13n's method is a lot simpler. Judging by the php coding you did is actually more sloppy.
You're no PHP coder to judge on that. They both did the same exact thing except Jurien didn't use variables. OP already did state that his use of variables was to make it easily configurable and you should respect that. Using an extra variable or two doesn't kill a website, does it?
Quote:
Originally Posted by Jur13n
WHERE DeleteFlag='0'
Integers don't freaking take ' '.
Re: [PHP] ODBC Top 25 Players for your site
Quote:
Originally Posted by
Vusion
You're no PHP coder to judge on that. They both did the same exact thing except Jurien didn't use variables. OP already did state that his use of variables was to make it easily configurable and you should respect that. Using an extra variable or two doesn't kill a website, does it?
Integers don't freaking take ' '.
That does work dumbass,
also, I was clearing up what superwaffle said,
not showing off like you do all day.
Re: [PHP] ODBC Top 25 Players for your site
First of all "jur13n" simplicity does not always mean better, It's more about Quality.
'deathtaker26's method would be much better to use in this situation because he is releasing this for beginners and along with the fact that he used the ODBC way to connect makes this even better cause of previous problems using only mssql doesn't work for everyone; Especially for ranking idk.
Good job making the variables / data more accessible and configurable [deathtaker25].
ps; If you're just quick coding a script for yourself and not releasing it then I would choose 'jur13n's method.
-correct me if i'm wrong