Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How To Display Selected Records From Database

Status
Not open for further replies.

cdogstu99

MIS
Jan 17, 2005
68
US
I have a page that i'm trying to create in asp with a list of 10 different products. I also have a database that the page is connecting to. It lists the names of all of my products (more than 10) with pricing. I'm trying to display the prices that i need for each of these products in the selected spot on this page. The only problem is i am unsure about how to set this up. I have been able to display the whole table, and 1 value, but I can't figure out how to go about displaying these selected values that i need. Here's the connection i used to display one of the selected prices on another page: (with the price display being <%=rs("Price1")%>
========================================

<%
' Name of the Accessdb being read
accessdb="database/pricelist2.mdb"


' Connect to the db with a DSN-less connection
cn="DRIVER={Microsoft Access Driver (*.mdb)};"
cn=cn & "DBQ=" & server.mappath(accessdb)

' Create a server recordset object
Set rs = Server.CreateObject("ADODB.Recordset")

' Select specific fields from the table the_bird
sql = "SELECT Price1 FROM gold_prices WHERE ID=4;"

' Execute the sql
rs.Open sql, cn
%>

Can someone tell me how to go about this if i need to pick 10 various prices from my table, where the sql would be comparable to this above? Thanks!!!
 
Did you mean this:

sql = "SELECT Top 10 Price1 FROM gold_prices WHERE ID=4;"

Provide some sample data and the kind of output you are looking for...

-DNG



 
Or perhaps you are seeking 10 distinct prices, in which case it would be something similar to:
Code:
sql = "SELECT TOP 10 DISTINCT Price1 FROM gold_prices WHERE ID=4"


------------------------------------------------------------------------------------------------------------------------
"I am not young enough to know everything."
Oscar Wilde (1854-1900)
 
no..if you take a look at this page i have:


take a look on the right where the coins are listed...i'm trying to use the asp to display the prices (which are shown in red) from my database. For each coin I have, I think i'll need to create a sql statement in order to select the correct price from the database...I'm just unsure how to set this up..(ie how to declare all of these different variables within one page) and display them where i need to...hope this clarifies.
 
sorry but i still didnt understand you...are you having problems with the sql query or with displaying the results of your query in particular spots...

-DNG
 
Yeah, i'm ok with setting up the queries, it's just how to display the results in different spots and how to set it up the coding in asp. My connection to my database is fine, i'm just confused on how to setup the variables in order to do what i need to do. thanks for getting back to me!
 
once the sql has been executed you could use response.write shortcut the value in the html code itself...will NOT work within asp tags

Code:
<%=price%>
 
Could you show me an example of how to do this? I'm still a bit lost on this one. Thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top