Pass dot in PHP to SQL query

I have a variable:

$orderby = orders.name;

$result = mysql_query(“SELECT * FROM orders,categories WHERE orders.catid = categories.id AND orders.complete = ‘$complete’ ORDER BY $orderby DESC”);

Since I can’t have the dot in $orderby. How can I pass it to the query, so that it orders by orders.name etc?

I am planning to use it in a query string, so should I use: admin.php?orderby=orders_name instead of orders.name? And how can I get the query formated correctly and use orders.name?

$orderby = ‘orders.name’;

You forgot to put the quotes around the string value ‘orders.name’

Hi,
Try $orderby like this:

$orderby = '`orders`.`name`';

Thanks for your responses.
Can I use a dot in the URL like this admin.php?orderby=orders.name ?
I noticed scripts like wordpress use an underscore

Try it :slight_smile:

If it doesn’t work, take a look at http://www.php.net/urlencode

Yes, you can use dot in URL like that.

I tried using a dot and it works good, but I have seen others are using underscores etc instead. Is it bad practice to use dots in the URL?

Personally, I use “-” as delimiter between words, so I get URL like “http://domain/some-interesting-article”. It is easily readable.

Anyway, in this particular case you are creating URL for administration, so it does not matter what is in the URL, if the delimiter is “.” or something else.