Cless Posted August 18, 2008 Share Posted August 18, 2008 Hello. Is there are way to order a query depending upon how many rows are located within that table? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/120137-ordering-by-mysql-row-amount/ Share on other sites More sharing options...
abdfahim Posted August 18, 2008 Share Posted August 18, 2008 Hey, I am not clear what you want. Can you plz explain more, may be with some practical example? Quote Link to comment https://forums.phpfreaks.com/topic/120137-ordering-by-mysql-row-amount/#findComment-618919 Share on other sites More sharing options...
Cless Posted August 18, 2008 Author Share Posted August 18, 2008 I was going to provide an example in the first place, however, I could not think of a way to explain it... anyway, I will attempt to. Um, if you had 3 rows within a table, would it be possible to make the query order by the number of rows? For example... $result= mysql_query("SELECT * FROM Table ORDER BY [NumberOfRows] DESC"); Quote Link to comment https://forums.phpfreaks.com/topic/120137-ordering-by-mysql-row-amount/#findComment-618922 Share on other sites More sharing options...
abdfahim Posted August 18, 2008 Share Posted August 18, 2008 Cless, I am still not clear. What do you mean by "order by the number of rows". Is it like that if there are 3 rows, 1st row comes first, then 2nd etc? Thre is no point of this though, coz it will come the sameway !! Else, if you said, it means "ORDER BY 3", i'll be more confused. Quote Link to comment https://forums.phpfreaks.com/topic/120137-ordering-by-mysql-row-amount/#findComment-618926 Share on other sites More sharing options...
Cless Posted August 18, 2008 Author Share Posted August 18, 2008 Ah, I phrased it incorrectly. Anyway, I just thought it over, and what I am attempting to achieve is impossible (though it can still be achieved in an alternate method which I will utilize instead). Quote Link to comment https://forums.phpfreaks.com/topic/120137-ordering-by-mysql-row-amount/#findComment-618928 Share on other sites More sharing options...
Nandini Posted August 18, 2008 Share Posted August 18, 2008 $rows=mysql_query("select * from table"); $num_rows=mysql_num_rows($rows); $result= mysql_query("SELECT * FROM Table ORDER BY $num_rows DESC"); Quote Link to comment https://forums.phpfreaks.com/topic/120137-ordering-by-mysql-row-amount/#findComment-618942 Share on other sites More sharing options...
MasterACE14 Posted August 18, 2008 Share Posted August 18, 2008 $rows=mysql_query("select * from table"); $num_rows=mysql_num_rows($rows); $result= mysql_query("SELECT * FROM Table ORDER BY $num_rows DESC"); that won't work. Quote Link to comment https://forums.phpfreaks.com/topic/120137-ordering-by-mysql-row-amount/#findComment-618945 Share on other sites More sharing options...
Nandini Posted August 18, 2008 Share Posted August 18, 2008 Yes exactly. You are correct MasterACE14. After ORDER BY it should fieldname only like 'id' etc. i think. Quote Link to comment https://forums.phpfreaks.com/topic/120137-ordering-by-mysql-row-amount/#findComment-618949 Share on other sites More sharing options...
.josh Posted August 18, 2008 Share Posted August 18, 2008 You need to specify a column name with ORDER BY. Think about it. If you had a list of fruit, and you wanted to order them, you could order by...alphabetically. Or by... shortest to longest word. But what you are trying to do is order by...3. What does 3 have to do anything with your list of fruit? How would I use "3" to determine which comes first, the orange or the banana? So do you now see how that makes no sense? So maybe you need to give a "before" and "after" example. Only other thing I can think of is, are you trying to order it differently, depending on how many rows are in the table? For instance, if there are 3 rows, you'd want to order them by columnA, but if there are 4, you want to order them by columnB? Quote Link to comment https://forums.phpfreaks.com/topic/120137-ordering-by-mysql-row-amount/#findComment-618950 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.