Jump to content

Archived

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

becu

How do I add...

Recommended Posts

here's my situation,
I want to select 9 rows from db and add 1 column for ranking purpose. What do I have to do?
example:

From db:
a----------aa
b----------bb
c----------cc
Here's what i want the output:
a----------aa----------1
b----------bb----------2
c----------cc----------3

Thanks.

Share this post


Link to post
Share on other sites
Easiest way to do this is with a user variable that you increment each time you find a new record that matches your query. Post what you have, and I'll give you an example.

Share this post


Link to post
Share on other sites
sorry, i got some problems with my internet connection...couldn't online till now.
ok, I will give you a more specific one:

[code]$result = mysql_query("SELECT title, singer FROM music order by vote desc limit 10");
if (!$result) {
   echo 'Could not run query: ' . mysql_error();
   exit;
}
while ($row = mysql_fetch_row($result))
{
echo $row[0]; // 42
echo $row[1]; // the email value
}
[/code]
Output:

Song 1-----Singer 1
Song 3-----Singer 3
Song 4-----Singer 4
Song 6-----Singer 6
Song 2-----Singer 2
Song 5-----Singer 5
Song 7-----Singer 7

What I want is:

Ranking-------------Title---------------------Singer
1--------------------Song 1------------------Singer 1
2--------------------Song 3------------------Singer 3
3--------------------Song 4------------------Singer 4
4--------------------Song 6------------------Singer 6
5--------------------Song 2------------------Singer 2
6--------------------Song 5------------------Singer 5
7--------------------Song 7------------------Singer 7
it's like top ten mtv.
Thank you so much!

becu.

Share this post


Link to post
Share on other sites
Well, in you want to do it in PHP, just create a count variable outside the while() loop, and increment it on the inside, and echo the value as your "ranking".

Share this post


Link to post
Share on other sites
ahhhh...I got it now...thank you so much fenway!!!!!

why am i so stupid anyway??? :(

Share this post


Link to post
Share on other sites

×

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.