becu Posted April 24, 2006 Share Posted April 24, 2006 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----------aab----------bbc----------ccHere's what i want the output:a----------aa----------1b----------bb----------2c----------cc----------3Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/8231-how-do-i-add/ Share on other sites More sharing options...
fenway Posted April 24, 2006 Share Posted April 24, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/8231-how-do-i-add/#findComment-30007 Share on other sites More sharing options...
becu Posted April 26, 2006 Author Share Posted April 26, 2006 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]; // 42echo $row[1]; // the email value}[/code]Output:Song 1-----Singer 1Song 3-----Singer 3Song 4-----Singer 4Song 6-----Singer 6Song 2-----Singer 2Song 5-----Singer 5Song 7-----Singer 7What I want is:Ranking-------------Title---------------------Singer1--------------------Song 1------------------Singer 12--------------------Song 3------------------Singer 33--------------------Song 4------------------Singer 44--------------------Song 6------------------Singer 65--------------------Song 2------------------Singer 26--------------------Song 5------------------Singer 57--------------------Song 7------------------Singer 7it's like top ten mtv.Thank you so much!becu. Quote Link to comment https://forums.phpfreaks.com/topic/8231-how-do-i-add/#findComment-30847 Share on other sites More sharing options...
fenway Posted April 27, 2006 Share Posted April 27, 2006 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". Quote Link to comment https://forums.phpfreaks.com/topic/8231-how-do-i-add/#findComment-31189 Share on other sites More sharing options...
becu Posted April 29, 2006 Author Share Posted April 29, 2006 ahhhh...I got it now...thank you so much fenway!!!!!why am i so stupid anyway??? :( Quote Link to comment https://forums.phpfreaks.com/topic/8231-how-do-i-add/#findComment-32050 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.