Results 1 to 2 of 2


  1. #1
    ioio Guest

    Default SQL -ORDER BY

    Hi,<BR>I have a database with a time, a date, a name and a ID column.<BR><BR>I know how to show all of them in ID order. (ORDER BY ID Desc)<BR>But how do I do if I want to show them by date (latest posts)?<BR>or name (a-z) or time?<BR><BR>And on the same page, like if you have a number of posts by ID order and then there are links that you can click on.<BR>Example. click here to view the list by date (latest posts first)<BR>And when you click, its the same page loading but the posts are in a different order.<BR><BR>AND does anyone know how the SQL code is when you want to view THE 5 latest posts from column.<BR>example:<BR>SQL.. SELECT * FROM Users(what shall I write next??)<BR>-----ANYONE KNOW?----<BR><BR>How can you order posts by pages? like, it should only be 10 posts per page. when the 11th post comes, it automatically changes to page 2, and the the 21st comes on page 3 and so and. I would also like to have a next page link and previous page link<BR><BR>Many questions...<BR>ioio<BR><BR>

  2. #2
    Pallermas Guest

    Default RE: SQL -ORDER BY

    «But how do I do if I want to show them by date (latest posts)?»<BR>You do the same:<BR>Ex:<BR>strSQL="SELECT * FROM Guestbook ORDER BY Date DESC, Time DESC"<BR><BR>To use links to sort the list another way, just use querystring:<BR>Ex:<BR>http://myweb.com/mysite/default.asp?sortby=name<BR>http://myweb.com/mysite/default.asp?sortby=ID<BR>http://myweb.com/mysite/default.asp?sortby=date<BR>etc...<BR><BR>in your default.asp you must have a select case on request.querystring("sortby") and then you put the code for each<BR>like :<BR>select case request.querystring("sortby")<BR> case name:<BR> strSQL = "SELECT * FROM Guestbook ORDER BY Name"<BR> case ID <BR> strSQL = "SELECT * FROM Guestbook ORDER BY ID"<BR>etc...<BR><BR>or just contact me if you want more code with explanations<BR><BR>fortin_jon@hotmail.com<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts