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

if so, can someone please tell me
thanks


$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)");

AND

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


but neither is working

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.

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()?

Member Avatar for rajarajan2017
Select * from tablename order by fieldname;

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

mysql_num_rows()

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.