| | |
Sorting Database Results
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jan 2007
Posts: 2
Reputation:
Solved Threads: 0
Okay, I'm working on a small project for my daughter's class at school. They have a fundraiser running right now and they want to post their fund raiser data on the their school website. What they want is this, they want a page listing each student and the amount that they've managed to raise so far along with a ranking.
Something like this:
Teresa H. $85 #1
Jana L. $84 #2
etc...etc...
This i've already accomplished. But they also want the ability to list the students alphabetically, which I can do also, but they each name to be clickable with a link to a page about that student containing information about their particular fundraising efforts. I guess a blog of sorts. And I have this written as well. The only thing I can't figure out is how to add each individual ranking to the individual pages.
To get the ranking above, I just select all the data from the db and use mysql_numrows($result); with a loop to get the "ranking" but I can't seem to figure this out when I have to use a select statement that requires that the userid be a match. Example:
Now how do I re-write my select statement to get my overall ranking for each student on their individual page?
Here's the basic db structure also:
uid, student_name, total_raised, homeroom
"total_raised" is the field that I'm using to get my Ranking.
Any help would be great b/c I'm stumped on this.
Something like this:
Teresa H. $85 #1
Jana L. $84 #2
etc...etc...
This i've already accomplished. But they also want the ability to list the students alphabetically, which I can do also, but they each name to be clickable with a link to a page about that student containing information about their particular fundraising efforts. I guess a blog of sorts. And I have this written as well. The only thing I can't figure out is how to add each individual ranking to the individual pages.
To get the ranking above, I just select all the data from the db and use mysql_numrows($result); with a loop to get the "ranking" but I can't seem to figure this out when I have to use a select statement that requires that the userid be a match. Example:
PHP Syntax (Toggle Plain Text)
$query = mysql_query("SELECT * FROM students where uid =$uid") or die(mysql_error());
Now how do I re-write my select statement to get my overall ranking for each student on their individual page?
Here's the basic db structure also:
uid, student_name, total_raised, homeroom
"total_raised" is the field that I'm using to get my Ranking.
Any help would be great b/c I'm stumped on this.
•
•
Join Date: Sep 2006
Posts: 44
Reputation:
Solved Threads: 3
How about something like:
This should tell you how many students have total_raised greater than the student you're looking at on your individual page... which should be equal to the ranking.
It should also handles ties just fine.
PHP Syntax (Toggle Plain Text)
select count(*) from students where total_raised > (select total_raised from students where uid=$uid)
It should also handles ties just fine.
![]() |
Similar Threads
- How to call a PHP function from Javascript and return the results back into Javascrip (PHP)
- PHP results in Blank Screen (PHP)
- Creating a Basic String Database (C++)
- Tutorial: Search a Database (ASP)
Other Threads in the PHP Forum
- Previous Thread: PHP and scheduled tasks
- Next Thread: Feature Posts on Index ?
| Thread Tools | Search this Thread |
# 5.2.10 alexa apache api array beginner binary broken cakephp checkbox class clean clients cms code cron curl database date directory display dissertation dropdown dynamic echo echo$_get[x]changingitintovariable... email encode error fairness file files folder form forms function functions google href htaccess html image images include indentedsubcategory insert ip javascript joomla legislation limit link local login mail memberships menu mlm multiple multipletables mysql mysqlquery newsletters oop open paypal pdf persist php problem provider query radio random recursion remote rss script search server sessions sms sockets source space spam sql syntax system table tutorial update upload url validator variable video web youtube





