PDA

View Full Version : Ranking by amount of hits


tek
03-14-2006, 12:01 AM
I'm gonna re-build my entire site after I've learned enough php from you and books and whatever resources you say are very useful (< question nr.1 :))

question nr.2:
If you look at my site http://www.game-kings.com you can see the amount of hits all games received and if you go to the games page you can simply see the game and that's it.

What I want to do is to show the games' rank on the games page just under the game (something like "This game has rank #455 out of 921 games".

The table name = mclinkscounter (yeah, I know, a free too easy script) & the row that stores the amount of hits = clic

I tried finding it in a 600 pages php book I have.. nowhere to be found.

And last but not least: does anyone know a good resource for learning how to do a vote script + all the extra's on it ofcourse?

I don't know if you need it or not, but I use this code to find the games' details in the table I use for that.


<?php
$id = (int)$_REQUEST['id'];
$query = "SELECT * FROM `objectfiles` WHERE `id` = '" . mysql_real_escape_string($id) . "'";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);

if($numrows < 1) {
echo "No such file";
exit;
}
else {
$row = mysql_fetch_array($result);

?>

<?php
<object><EMBED SRC="<?=$row[src]?>" width="<?=$row[width]?>" height="<?=$row[height]?>"></object>
?>

goughy000
03-14-2006, 04:55 PM
It would be so much easier if the hits were in the same table as the game data...

then you could do something like ordering your results

i dno.. just some ideas for you to think about

tek
03-14-2006, 06:22 PM
yeah, that's what I'm gonna do when I know enough php to re-write the whole site.

Don't know if anyone is interested, but if someone is interested in writing a flash games portal with me, send me a message (can even hook you up with a test directory on my server :p).

Btw, and an answer to the other 2 questions?

goughy000
03-14-2006, 06:33 PM
i mainly use forums dedicated to coding or PHP, the php website is useful for syntax for different commands...

www.php.net/<commandname>

will give you documentation on all the commands

phpfreaks is good too.


Voting system...
you can probably find one on google... why dont you use a portal? like e107 or PHPnuke

tek
03-14-2006, 10:54 PM
because I'll probably start a programming study after this summer and I'd like to have a head start to make it a bit easier.

and writing a total games portal is a good step because it requires a lot of different things.

php.net is a good resource... if you know the functions' names... but I don't :p

goughy000
03-16-2006, 11:07 PM
i guess a lot of function names, and the search that comes up on php.net is usually good enough to find me what i want.

in reply to the PM you sent me...

I checked your reply again and was quite interested in how I could make a code for the ranks if both tables were stored in 1 table.

if they were both stored in one table...


gamename | description | hits
--------------------------------
game1 |cool stuff | 3
game2 |coolER stuff | 9


then


<?php
//Connect and select db
mysql_connect("localhost", "root", "psswd");
mysql_select_db("database1");

// Query, ordered by hits
$result = mysql_query("SELECT * FROM gamestable ORDER BY hits DESC");

// Set variable
$rank = 1;

// Prepare a html table
echo "<table border=\"0\"><tr><td>Game Name</td><td>Description</td><td>Hits</td><td>Rank</td></tr>";

//Loop through results
while($row = mysql_fetch_array($result)){
// Echoing data
echo "<tr><td>" . $row['gamename'] . "</td><td>" . $row['description'] . "</td><td>" . $row['hits'] . "</td><td>" . $rank . "</td></tr>";
// add one to rank for next result
$rank++;
}
// End html table
echo "</table>";
?>


thats jus something to start with...

tek
03-17-2006, 12:07 AM
and what do I use if I want the rank for the game that someone's playing?

something like:

<?php
//Connect and select db
mysql_connect("localhost", "root", "psswd");
mysql_select_db("database1");

// Query, ordered by hits
$result = mysql_query("SELECT * FROM gamestable WHERE id=$id ORDER BY hits DESC LIMIT 0, 1");

// Set variable
$rank = 1;

// Prepare a html table
echo "<table border=\"0\"><tr><td>Game Name</td><td>Description</td><td>Hits</td><td>Rank</td></tr>";

//Loop through results
while($row = mysql_fetch_array($result)){
// Echoing data
echo "<tr><td>" . $row['gamename'] . "</td><td>" . $row['description'] . "</td><td>" . $row['hits'] . "</td><td>" . $rank . "</td></tr>";
// add one to rank for next result
$rank++;
}
// End html table
echo "</table>";
?>


the WHERE id=$id part is for the id of the game (the id is set in the code that I use to load the games data) and the LIMIT 0, 1 part would be to limit the result to only 1 entry?

or would I have to use a totally different entry for the $rank variable because with this, it seems it will only give a "1" as a result?

goughy000
03-17-2006, 01:56 PM
<?php
//Connect and select db
mysql_connect("localhost", "root", "psswd");
mysql_select_db("database1");

// Query, ordered by hits
$result = mysql_query("SELECT * FROM gamestable ORDER BY hits DESC");

// Set variable
$rank = 1;

// Prepare a html table
echo "<table border=\"0\"><tr><td>Game Name</td><td>Description</td><td>Hits</td><td>Rank</td></tr>";

//Loop through results
while($row = mysql_fetch_array($result)){
// Echoing data
// If the result from the query is the one we want, echo it
if($row['id'] == $id){
echo "<tr><td>" . $row['gamename'] . "</td><td>" . $row['description'] . "</td><td>" . $row['hits'] . "</td><td>" . $rank . "</td></tr>";
}
// add one to rank for next result
$rank++;
}
// End html table
echo "</table>";
?>

Probably not the best way