just_a_girl — 2011-09-29T09:22:25-04:00 — #1
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?
guido2004 — 2011-09-29T09:26:41-04:00 — #2
$orderby = 'orders.name';
You forgot to put the quotes around the string value 'orders.name'
marplo — 2011-09-29T09:27:52-04:00 — #3
Try $orderby like this:
$orderby = '`orders`.`name`';
just_a_girl — 2011-09-29T09:32:10-04:00 — #4
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
guido2004 — 2011-09-29T09:34:00-04:00 — #5
If it doesn't work, take a look at http://www.php.net/urlencode
jake_polak — 2011-10-01T16:55:30-04:00 — #6
Yes, you can use dot in URL like that.
just_a_girl — 2011-10-01T17:02:31-04:00 — #7
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?
jake_polak — 2011-10-01T17:11:42-04:00 — #8
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.