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!