Jump to content


Photo

How do I add...


  • Please log in to reply
4 replies to this topic

#1 becu

becu
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 24 April 2006 - 04:56 AM

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.

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 24 April 2006 - 07:16 AM

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.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 becu

becu
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 26 April 2006 - 05:50 AM

sorry, i got some problems with my internet connection...couldn't online till now.
ok, I will give you a more specific one:

$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
}
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.

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 27 April 2006 - 03:14 AM

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".
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 becu

becu
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 29 April 2006 - 10:50 PM

ahhhh...I got it now...thank you so much fenway!!!!!

why am i so stupid anyway??? :(




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users