Jump to content

[SOLVED] String function still gives wrong reply here ..


EchoFool

Recommended Posts

I have a query which gets the position of the row in the table onced ordered then a function that gets that number and displays it in a ranking..... but i keep getting the same response of "2th" every time .. (the number in this example is 2).

Code:

 

<?php
function ordinal($n) {
if($n == '11' ||
$n == '12' ||
$n == '13'
){
$suff = 'th';
}elseif($n == '1'){ $suff = 'st'; }
elseif($n == '2'){ $suff = 'nd'; }
elseif($n =='3'){ $suff = 'ed'; }
else { $suff = 'th'; }
return $n . $suff;
}
?>

<?php
function position($Field,$ID){
$Get = mysql_query("SELECT COUNT(t2.$Field) + 1 AS position FROM listings t1
			LEFT OUTER JOIN listings t2
					ON t1.$Field < t2.$Field
			WHERE t1.ID = '$ID'")	
				Or die(mysql_error());		
$row = mysql_fetch_assoc($Get);
Echo $row['position'];
}
?>

<?php
If(isset($_GET['view'])){
$ID = strtolower(mysql_real_escape_string(stripslashes($_GET['view'])));
$Check = mysql_query("SELECT * FROM listings WHERE Authorised='1' AND ID='$ID'")
Or die(myslq_error());
If(mysql_num_rows($Check)>0){
$row = mysql_fetch_assoc($Check);
$GameID = $row['GameID'];
Echo 'You listing is currently ranked: '.ordinal(position('VotesIN',$GameID)).'<br>';
}
}
?>

 

Result:

Your listing is currently ranked: 2th

 

Not sure where its going wrong here? Help :(

 

 

The re

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.