Jump to content

nkls

New Members
  • Posts

    5
  • Joined

  • Last visited

nkls's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. got it all sorted out =) thanks a lot!
  2. thanks for helping me berand, but I still cant get it to work. I feel a bit stupid, hope you can bare with me. my udid comes from a $udid = $_GET['udid'];, and that seems to work. My table is namned myTable, and my version of your "name" is udid. the score is called score.. would this be correct?: $sql = "SELECT a.udid , a.score , COUNT(b.udid)+1 as rank , tot FROM myTable a JOIN (SELECT COUNT(udid) as tot FROM myTable) as total LEFT JOIN myTable b ON b.score > a.score WHERE a.udid = $udid GROUP BY a.udid ORDER BY a.score DESC;"; I really appreciate your help!
  3. hmm, ok. I just want the position of the user i pass in (by udid) based on his/her score.. ideally i would like the output of my echo to be something like this: 14th of 200 where 14 is user position based on score and 200 is total scores..
  4. wow, I love Internet! Works great, thanks! May I ask you one more thing? This gives me my position in the table based on the id-sorting. If i want to sort my table on score before doing this, where would i put my ORDER BY score? Sorry, totally new on this..
  5. Hi! I´m learning PDO at the moment, but struggling a bit.. I want to get a specific users position in my highscore. I would lite the output to be like "your position is 14th of 200. I have tried to search, but i cant get it to work at all :/ Im using an uniqe string as udid, and want to get the rank of that udid based on score... the connection works but something is wrong in my sql statement.. try { $conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo "Connected successfully"; } catch(PDOException $e) { echo "Connection failed: " . $e->getMessage(); } $udid = $_GET['udid']; function getUserRanks($udid, $conn) { $sql = "SELECT COUNT(udid) AS `rank` FROM myTable WHERE score > ( SELECT score from myTable WHERE udid = $udid )"; $stmt = $conn->prepare($sql); $stmt->bindValue(1, $udid); $stmt->execute(); $ranks = $stmt->fetchObject(); return $ranks; } $ranks = getUserRanks($udid, $conn); echo $ranks; ?> im getting this error: "Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'myLongUdidStringHere'" Would be very happy if someone could help me with my function or point me in the right way! Thanks a lot!
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.