The query string needs to be enclosed in ""
.
Does the segment of code you provided work? Some things to check if it does not:
1) Make sure that your $connect
information is correct.
2) Make sure that table
is the name of your table.
3) Make sure that activ
is a column in your table. And the values stored there are of Boolean data type.
4) Make sure that date
is a column in your table and the date type you are using is correctly stored in the table.
5) Note that LIMIT
is expecting an argument of number of records to return from some offset, based on the variable names you are using $start
and $end
, I am assuming you are using LIMIT
incorrectly. More appropriately $number_of_records
and $offset
.
6) Check the error logs to see if there is an error being logged either by the database server or the domain server itself.
Now if that query works...
Matt Clark handled the rest of the question about ASC
and DESC
below, see here. But obviously you can't just stick ASC
or DESC
without specifying a key to sort by, such as the column date
. So the query string would look like this:
"SELECT * FROM table WHERE activ = '1' ORDER BY date $order LIMIT $start, $end"
Another option if your queries get more complex and are not only related to sorting by date, then you might resort to providing multiple variables with your URL.
mysite.com/index.php?sortby=date&order=newest
"SELECT * FROM table WHERE activ = '1' ORDER BY $sortby $order LIMIT $start, $end"
You can learn more about multiple variables in a URL from this post: Passing multiple variables to another page in url and others like it.