Mutley Posted November 8, 2008 Share Posted November 8, 2008 I'm wanting to find and echo the row position in a table when they are put into order and there is a certain where clause. For example, I want to find what row position it is where ID = 7... ordered by `joindate`. This might bring up 10 results, where the row with the above ID (7) is 5th in the results. How do I echo "5"? I hope that makes sense. Thanks, Nick. Quote Link to comment https://forums.phpfreaks.com/topic/131936-row-position-in-database/ Share on other sites More sharing options...
BillyBoB Posted November 8, 2008 Share Posted November 8, 2008 One question before I start any coding, what is this used for? Quote Link to comment https://forums.phpfreaks.com/topic/131936-row-position-in-database/#findComment-685449 Share on other sites More sharing options...
Mutley Posted November 8, 2008 Author Share Posted November 8, 2008 It's for a Leaderboard. They have a number assigned to their position but this isn't stored in a database, it's simply by looping a count (e.g. $count = 0; $count++) when the results are displayed. When a certain event happens I want this number to be stored in the database but the file the event in isn't linked to this Leaderboard, so I can't pass the $count over in anyway (like POST/GET or whatever). Thanks, Nick. Quote Link to comment https://forums.phpfreaks.com/topic/131936-row-position-in-database/#findComment-685471 Share on other sites More sharing options...
BillyBoB Posted November 8, 2008 Share Posted November 8, 2008 This might seem ridiculous but I would try to use AJAX. This doesn't require the file to be on your server at all. Where is the file that does the count at? Quote Link to comment https://forums.phpfreaks.com/topic/131936-row-position-in-database/#findComment-685502 Share on other sites More sharing options...
Mutley Posted November 8, 2008 Author Share Posted November 8, 2008 I don't know a thing about AJAX. The event that needs the number is in a file with loads more code. I'm slightly confused by your question, sorry. ??? Quote Link to comment https://forums.phpfreaks.com/topic/131936-row-position-in-database/#findComment-685508 Share on other sites More sharing options...
BillyBoB Posted November 8, 2008 Share Posted November 8, 2008 In your database did you not setup ID as a unique index? Quote Link to comment https://forums.phpfreaks.com/topic/131936-row-position-in-database/#findComment-685515 Share on other sites More sharing options...
Mutley Posted November 8, 2008 Author Share Posted November 8, 2008 Yep I did. Quote Link to comment https://forums.phpfreaks.com/topic/131936-row-position-in-database/#findComment-685550 Share on other sites More sharing options...
Barand Posted November 8, 2008 Share Posted November 8, 2008 As you list the sorted results, increment a counter and echo its value. Quote Link to comment https://forums.phpfreaks.com/topic/131936-row-position-in-database/#findComment-685556 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.