Hi all I am new to asp and had a question, I have a database driven site and
would like to have an option showing the last 10 records added to the
database, does anyone know if a) this is possible and b) how to do it?
Thanks alot.

Re: ASP Question by Bob

Bob
Sat May 08 14:53:03 CDT 2004

SELECT TOP 10 <fields> FROM <table_name> ORDER BY <field_name> DESC.

The first item in your fields list is the one the TOP clause will apply to.

Bob Lehmann

"donald" <donaldmarshall@ntlworld.com> wrote in message
news:utkPy2RNEHA.620@TK2MSFTNGP10.phx.gbl...
> Hi all I am new to asp and had a question, I have a database driven site
and
> would like to have an option showing the last 10 records added to the
> database, does anyone know if a) this is possible and b) how to do it?
> Thanks alot.
>
>



Re: ASP Question by donald

donald
Sat May 08 15:23:45 CDT 2004

Thanks so I would put a piece of aspcode that reads

<? SELECT TOP 10 Titles FROM DVD ORDER BY Title DESC ?>

?

Thanks alot



Re: ASP Question by Roland

Roland
Sat May 08 17:22:52 CDT 2004

"donald" wrote in message news:uKpwcpTNEHA.2780@TK2MSFTNGP09.phx.gbl...
: Thanks so I would put a piece of aspcode that reads
:
: <? SELECT TOP 10 Titles FROM DVD ORDER BY Title DESC ?>

? is not ASP. See PHP.

--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center - http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation - http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library - http://msdn.microsoft.com/library/default.asp



Re: ASP Question by Bob

Bob
Sat May 08 22:43:19 CDT 2004

Well, yeah, if you are using ASP, and - I assume Access or SQL Server.

Except, since it looks like you are using PHP, and Lord knows what DB
(<shiver>MySQL</shiver> or PostGres), I can't say for sure.

What happened when you tried it?

Bob Lehmann

"donald" <donaldmarshall@ntlworld.com> wrote in message
news:uKpwcpTNEHA.2780@TK2MSFTNGP09.phx.gbl...
> Thanks so I would put a piece of aspcode that reads
>
> <? SELECT TOP 10 Titles FROM DVD ORDER BY Title DESC ?>
>
> ?
>
> Thanks alot
>
>



Re: ASP Question by donald

donald
Sun May 09 01:55:56 CDT 2004

No I am using ASP and MS Access, I am new to ASP as I said so when I typed
the email I made the mistake of using PHP code, Iam still learning after all
:)

So can you please tell me the correct code to use?
Much appreciated.



Re: ASP Question by donald

donald
Sun May 09 02:37:28 CDT 2004

Did it again sorry not with it today, I had already tried
<%
Response.Write(SELECT TOP 10 Titles FROM DVD ORDER BY Title DESC)
%>

but that just gives me a 500.100 error saying

Error Type:
Microsoft JScript compilation (0x800A03EE)
Expected ')'
/index.asp, line 21, column 22
Response.Write(SELECT TOP 10 Titles FROM DVD ORDER BY Title DESC)

Thanks for any help much appreciated.



Re: ASP Question by Aaron

Aaron
Sun May 09 11:53:44 CDT 2004

<%
// you'll need to fix this line:
dbPath = Server.MapPath("/file.mdb")

Set conn = CreateObject("ADODB.Connection")
conn.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & dbPath

sql = "SELECT TOP 10 Titles FROM DVD ORDER BY Title DESC"
Set rs = conn.execute(sql)

do while not rs.eof
response.write rs(0) & "<br>"
rs.movenext
loop

rs.close: set rs = nothing
conn.close: set conn = nothing
%>


--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/


"donald" <donaldmarshall@ntlworld.com> wrote in message
news:OCGG9hZNEHA.3988@TK2MSFTNGP09.phx.gbl...
> Did it again sorry not with it today, I had already tried
> <%
> Response.Write(SELECT TOP 10 Titles FROM DVD ORDER BY Title DESC)
> %>
>
> but that just gives me a 500.100 error saying
>
> Error Type:
> Microsoft JScript compilation (0x800A03EE)
> Expected ')'
> /index.asp, line 21, column 22
> Response.Write(SELECT TOP 10 Titles FROM DVD ORDER BY Title DESC)
>
> Thanks for any help much appreciated.
>
>



Re: ASP Question by Bob

Bob
Sun May 09 14:55:12 CDT 2004

Not sure what the Response Write is all about. If you want to write it out
to the browser it would be...
Response.Write("SELECT TOP 10 Titles FROM DVD ORDER BY Title DESC")
Note the quotes.

The ordinary sequence is.....

Assign query to a variable
Create Connection object
Open connection
Execute SQL statement
Display results
Close result & set to Nothing
Close connection & set to Nothing

Aaron's example is a good implementation of this.

Bob Lehmann



"donald" <donaldmarshall@ntlworld.com> wrote in message
news:OCGG9hZNEHA.3988@TK2MSFTNGP09.phx.gbl...
> Did it again sorry not with it today, I had already tried
> <%
> Response.Write(SELECT TOP 10 Titles FROM DVD ORDER BY Title DESC)
> %>
>
> but that just gives me a 500.100 error saying
>
> Error Type:
> Microsoft JScript compilation (0x800A03EE)
> Expected ')'
> /index.asp, line 21, column 22
> Response.Write(SELECT TOP 10 Titles FROM DVD ORDER BY Title DESC)
>
> Thanks for any help much appreciated.
>
>