affc Posted May 6, 2009 Share Posted May 6, 2009 Hello, Just trying to display the number of each person individually from a table so that I can single out the individual rank for each person: I get this error: Parse error: syntax error, unexpected T_LNUMBER, expecting T_VARIABLE or '$' at ((( $individualrank[]=$rank; ))) For some reason it wont let me get the rank of ++$rank so I can view each persons rank individually when I post a search result for that person. Thanx in advance if anyone can help me here <?php $sql="SELECT * FROM $tbl_name ORDER BY TOTAL DESC, UserName ASC"; $result=mysql_query($sql); $counter=mysql_num_rows($result); $rank=0; while($rows=mysql_fetch_array($result)){ ++$rank; $individualrank[]=$rank; $Checkusername[]=$rows['UserName']; } for($i=0;$i<$counter;$i++){ if($Checkusername[$i]==$_POST['username']){ echo $$individualrank[$i]; } } ?> Link to comment https://forums.phpfreaks.com/topic/157041-solved-individual-rank-of-each-user/ Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 You have an extra $ in your echo. Link to comment https://forums.phpfreaks.com/topic/157041-solved-individual-rank-of-each-user/#findComment-827238 Share on other sites More sharing options...
affc Posted May 6, 2009 Author Share Posted May 6, 2009 Sorry that was actually just a personal error I have changed now but still no good, the error is coming from trying to get the number of each row using the ++ <?php $sql="SELECT * FROM $tbl_name ORDER BY TOTAL DESC, UserName ASC"; $result=mysql_query($sql); $counter=mysql_num_rows($result); $rank=0; while($rows=mysql_fetch_array($result)){ $individualrank[]=++$rank; $Checkusername[]=$rows['UserName']; } for($i=0;$i<$counter;$i++){ if($Checkusername[$i]==$_POST['username']){ echo $individualrank[$i]; } } ?> Link to comment https://forums.phpfreaks.com/topic/157041-solved-individual-rank-of-each-user/#findComment-827244 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 Is $tbl_name defined anywhere? Link to comment https://forums.phpfreaks.com/topic/157041-solved-individual-rank-of-each-user/#findComment-827245 Share on other sites More sharing options...
affc Posted May 6, 2009 Author Share Posted May 6, 2009 Yeah, if I do the following I get this result: <?php while($rows=mysql_fetch_array($result)){ echo ++$rank; echo $rows['UserName']; ?> } Result = 1 Peter 2 Tom 3 Garry 4 Sally 5 Gill etc etc etc but i dont want to echo all of them, only want to display 1 person I have searched for with the POST function but still show their rank etc. Link to comment https://forums.phpfreaks.com/topic/157041-solved-individual-rank-of-each-user/#findComment-827252 Share on other sites More sharing options...
Ken2k7 Posted May 6, 2009 Share Posted May 6, 2009 <?php $sql="SELECT * FROM $tbl_name ORDER BY TOTAL DESC, UserName ASC"; $result=mysql_query($sql) or die(mysql_error()); $rank=0; while($rows=mysql_fetch_array($result)){ ++$rank; if($rows['UserName']==$_POST['username']){ echo $rank; } } ?> Like that? Link to comment https://forums.phpfreaks.com/topic/157041-solved-individual-rank-of-each-user/#findComment-827259 Share on other sites More sharing options...
affc Posted May 6, 2009 Author Share Posted May 6, 2009 WOW!!! lol, that is awesome. I am still getting my head around how that actually works but thank you so much. Wish I was that smart at php, still learning lol but thank you so much Link to comment https://forums.phpfreaks.com/topic/157041-solved-individual-rank-of-each-user/#findComment-827271 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.