Forum Moderators: coopster

Message Too Old, No Replies

help pls

         

sctsree

7:29 pm on Nov 16, 2009 (gmt 0)

10+ Year Member



hi..i have a quiz site wherein there are 35 levels.There is a leader board which shows the points of all players.
when he crosses level 1 the leader board should update his score..like add one to his score and put him on top of the table [if he is the top scorer]..how is this possible?

The question is put up in 1.php the answer to be compared is in 2.php and the next level is 3.php

what is the sql query to create a field for this?
how will 2.php handle this to update the leaderboard?thanku in advance..

skinsey

9:20 am on Nov 20, 2009 (gmt 0)

10+ Year Member



You would create a table called tablename with fields
player_name
position
score

after each level

//count all scores equal to or less than score.
$query="SELECT * FROM tablename WHERE score <= $score";
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);

//start at end and move each position up by 1
for($i = $num_rows; $i >= $position; $i--)
{
$position = $i + 1;

$query= "Update tablename SET position ='$position' WHERE player_name ='$player_name' AND position = '$i'";
$temp = mysql_query($query)
or die(mysql_error());
}

//pu your code below to insert new record

skinsey

9:22 am on Nov 20, 2009 (gmt 0)

10+ Year Member



update should of been

$query= "Update tablename SET position ='$position' WHERE position = '$i'";

sctsree

5:50 am on Nov 23, 2009 (gmt 0)

10+ Year Member



could u explain?