PDA

View Full Version : Display only Ferrari's


The Wizzard
03-09-2003, 08:00 PM
Hey Everyone,

Im working on my car site, and what im trying to do is, I have 5 cars on the main page, BMW, Lexus, Ferrari, Porsche, Mercedes

What I want to do is, when someone clicks on, lets say, Ferrari, i want my results to ONLY display Ferrari's. Not any other cars from the database, same with all the other cars i click on.

The field name is "Make" in my database

scroots
03-09-2003, 08:07 PM
is it an access database? as i have some code if it is.

scroots

The Wizzard
03-09-2003, 08:12 PM
Yep

pinkcat_02
03-09-2003, 08:12 PM
try to use the sql like:

select * from Table where car_name='Ferrari'

you can use this code if you keep all the cars in one table in your database and have a field called car_name or whatever that indicated the name of the cars.

The other option can be designing different tables for every car range in your case 4 tables one for each range and keep details there where u can use the sql:

select * from Ferrari


like I said before it depends on your database design...

Hope this helps.

The Wizzard
03-09-2003, 08:43 PM
Okay, this is good...

What if im using querystrings?

results.asp?make=ferrari

pinkcat_02
03-09-2003, 09:15 PM
then u need to change the sql in the result.asp to allow it to show the details of the car where ferrari is selected.

' Get the requested car range from the request object
' For example, if the request car object was "result.asp?car=ferrari"
' then Request("Car") would return 21

m_sSourceID = Request("Car")

SQL = "SELECT *FROM table"
SQL = SQL & " WHERE Id = " & m_sSourceID

pinkcat_02
03-09-2003, 09:18 PM
then u need to change the sql in the result.asp to allow it to show the details of the car where ferrari is selected.

' Get the requested car range from the request object
' For example, if the request car object was "result.asp?car=ferrari"
' then Request("Car") would return ferrari

m_sSourceID = Request("Car")

SQL = "SELECT *FROM table"
SQL = SQL & " WHERE Id = " & m_sSourceID

dominicall
03-11-2003, 04:41 AM
Hi Wizzard

One tip you should definitely use is not to do the select using text from querystring/form but using the id of the make, i.e.

Have one table for the makes with a UID column and make column, as below:
MakeID Make
1 Ferrari
2 Mercedes
......
and a separate table for the car details...
ModelID MakeID Model ADetail ANODetail
1 1 250GTO Expensive But worth it
etc....
Then to select all Ferraris, instead of using:
Dim make: make = Request.QueryString("make")
"SELECT * FROM tbl_Cars WHERE make='" & make & "';"

...in this instance make = Ferrari
you should use...
Dim makeid:makeid = Request.QueryString("makeid")
SELECT * FROM tbl_Cars WHERE MakeID = " & makeid & ";"

...and in this instance makeid = 1
Your searches will be quicker as Access (like all databases) will search much more quickly against integers than strings and you'll put less strain on the database - especially important when using Access.

I don't know, so please don't take this the wrong way, but if you've not done much relational database design in the past I definitely recommend reading up on database normalization - will make a significant difference - not only to your coding but the performance of your sites.

If you're already a genius then please accept my apologies for making the assumption above.

Hope that helps.

dominicall :D