is it possible to order a query by another query by mysql_num_rows?

if so, can someone please tell me

$query2 = doquery("SELECT id FROM table_name2 WHERE id='$thisid'");
$idcount = mysql_num_rows($query2);

I tried this:

$query = doquery("SELECT * FROM table_name ORDER by mysql_num_rows($query2)");


$query = doquery("SELECT * FROM table_name ORDER by $idcount");

but neither is working

Edited by griffith: n/a

7 Years
Discussion Span
Last Post by scaiferw

I'm afraid you've lost me here.

mysql_num_rows() will return an integer. I'm not sure how or why you would sort by an integer. Unless this is some tricky SQL syntax I've never heard of, you can only order by a field name (or alias), not by an integer.

BTW, it's a lot easier for people to help you if you put your code samples in code-tags.

Edited by mike_2000_17: Fixed formatting


oh ok i was just wondering, k thanks, i will remember that next time also.

what's an alias?

And is it possible to update a query using mysql_num_rows()?

Edited by griffith: n/a

Select * from tablename order by fieldname;

The query shows that should be a fieldname after order by never comes an integer.


The above php code used to return the no of rows in the table executed by our query.
you can use this syntax to check whether your query return any rows from the table or not retreiving any rows from the table.

Alias is the temporary dummyname for fields or table you can use within your query

Select sum(quantity) as Total from sales;

Here the Total is the alias name.


To clarify, mysql_num_rows() can only tell you thr number of rows returned by a query.
You can't use it to update a table, unless for some reason you wanted to use the integer it returns as a value in an insert or update statement.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.