Page 1 of 1

mysqp order by issue

Posted: Thu Jun 18, 2009 10:10 am
by cardi777
Hi all. I can't figure out why my code ain't working!?

Code: Select all

$query_table = "SELECT * FROM sys_fields WHERE db_table_name = '$db_table_name' ORDER BY '$order' '$dir'";
What am I doing wrong? The issue is that "order by" isn't doing anything. No errors show. Just lacking functionality.

I used the same code on another table, but it didn't have a "where" statement - it worked fine.

Confused :P

Cheers,
Doug

Re: mysqp order by issue

Posted: Thu Jun 18, 2009 10:21 am
by Mark Baker
cardi777 wrote:What am I doing wrong? The issue is that "order by" isn't doing anything. No errors show either.
Why are you quoting the table name, order by column and direction?

Code: Select all

$query_table = "SELECT * FROM sys_fields WHERE db_table_name = $db_table_name ORDER BY $order $dir";
Print out the value of $query before executing the mysql_query, to be sure that the variables have substituted as you expect.
Trap for errors with or die(mysql_error())

Re: mysqp order by issue

Posted: Sun Jun 21, 2009 7:25 am
by cardi777
There is an or die in place.

Here is my result, first line is an eho of the query. 2nd line is the error which appeared after it:

Code: Select all

SELECT * FROM sys_fields WHERE db_table_name = table_test33 ORDER BY f_pos ASC
Unknown column 'table_test33' in 'where clause'
But if I do this...

Code: Select all

SELECT * FROM sys_fields WHERE db_table_name = 'table_test33' ORDER BY 'f_pos' 'ASC'
.. the data shows, but the ordering isn't functional :P

.. i really don't get it. This column DOES exist. And this query works fine if I take away "ORDER BY f_pos ASC".

Any other suggestions? Really stuck on this one.

Re: mysqp order by issue

Posted: Sun Jun 21, 2009 7:30 am
by cardi777
ahh i figured it out...

this is the query that works.. believe it or not...

Code: Select all

$query_table = "SELECT * FROM sys_fields WHERE db_table_name = '$db_table_name' ORDER BY $order $dir";
Thanks for your help anyway - incase anyone has this same issue, im glad hope this topic will help someone somehow.

Cheers,
Doug