EchoFool Posted June 18, 2009 Share Posted June 18, 2009 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 Link to comment https://forums.phpfreaks.com/topic/162824-solved-string-function-still-gives-wrong-reply-here/ Share on other sites More sharing options...
EchoFool Posted June 18, 2009 Author Share Posted June 18, 2009 That last bit was meant to say " The response to it is" Your listing is currently ranked: 2th Link to comment https://forums.phpfreaks.com/topic/162824-solved-string-function-still-gives-wrong-reply-here/#findComment-859244 Share on other sites More sharing options...
papillonstudios Posted June 18, 2009 Share Posted June 18, 2009 ok in your ordinal function what happens if you change <?php $suff = 'th'; ?> to lets say <?php $suff = 'help'; ?> Link to comment https://forums.phpfreaks.com/topic/162824-solved-string-function-still-gives-wrong-reply-here/#findComment-859246 Share on other sites More sharing options...
PFMaBiSmAd Posted June 18, 2009 Share Posted June 18, 2009 It's likely that your data isn't exactly just '2'. Have you checked using var_dump() to see exactly what it is? Link to comment https://forums.phpfreaks.com/topic/162824-solved-string-function-still-gives-wrong-reply-here/#findComment-859248 Share on other sites More sharing options...
EchoFool Posted June 18, 2009 Author Share Posted June 18, 2009 It's likely that your data isn't exactly just '2'. Have you checked using var_dump() to see exactly what it is? Good thinking it returned this: string(1) "2" So its returning as non numerical value am i right here? Link to comment https://forums.phpfreaks.com/topic/162824-solved-string-function-still-gives-wrong-reply-here/#findComment-859262 Share on other sites More sharing options...
PFMaBiSmAd Posted June 18, 2009 Share Posted June 18, 2009 Your position() function does not return anything, so it will be a little hard for your ordinal() function to operate on anything. Link to comment https://forums.phpfreaks.com/topic/162824-solved-string-function-still-gives-wrong-reply-here/#findComment-859268 Share on other sites More sharing options...
EchoFool Posted June 18, 2009 Author Share Posted June 18, 2009 Oh of course.. cos im echo'in it.... its not carrying the variable into my ordinal function ? Link to comment https://forums.phpfreaks.com/topic/162824-solved-string-function-still-gives-wrong-reply-here/#findComment-859276 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.