Newbie needs help for advanced database search

Results 1 to 3 of 3

Thread: Newbie needs help for advanced database search

  1. #1
    Vadim Guest

    Default Newbie needs help for advanced database search

    Hi,<BR><BR>I want to create a search where the user can query the database with various questions. This is for a camera site. Querying and reporting the Make, Model, Price range and Camera type. <BR><BR>How do I go about implementing this if the user only enters say one field leaving the rest blank? How do I build my SQL query from that? <BR><BR>Help!!<BR><BR>-Vadim

  2. #2
    iyyappan n iyer Guest

    Default Construct query with user typed values

    get values from user and construct query at runtime and execute it to get results.<BR>for example<BR><BR>Sql1 = "Select * From Cameras Where Brand =&#039" & Request.QueryString("Brand") &"&#039"<BR>Rs.Open Sql1, Conn,2,2<BR><BR>&#039***********<BR>if u have very complicated query create a rs of the whole table and loop to check each record manually.<BR><BR>&#039*********<BR>try the first method, to begin with.

  3. #3
    Join Date
    Dec 1969

    Default a few ideas

    why not have drop down boxes for Make, Model and Camera Type which are populated from the records actually on the database<BR>by something like<BR><BR>SELECT DISTINCT Make FROM CameraTable<BR><BR>you could then dynamically alter what is available for selection in one drop down box based on what is selected in another. I.E If you select Make "Pentax" you only put Pentax models in the Model drop down and don&#039t show "Cannon" models.<BR><BR><BR>you would also have to add a selection "all" to the drop down boxes then you&#039d build the query something like<BR><BR>mySQL = "SELECT * FROM CameraTable"<BR>if request.form("Make") != "all" then<BR> mySQL = mySQL & "WHERE Make=&#039" & request.form("Make") & "&#039"<BR>end if<BR><BR>obviously your conditions here would be more complex because you have more than one field to consider.<BR><BR>ALTERNATIVELY - this is not as nice for the user imho, but easier to code. Just have one search string text box and do a query as follows<BR><BR>mySQL = "SELECT * FROM CameraTable WHERE Make LIKE &#039%" & _<BR> request.form("SearchString") & "%&#039 OR" _ &<BR> "Model LIKE &#039%" & request.form("SearchString") & "%&#039 OR" _ &<BR><BR> ....ETC...<BR><BR><BR>hope this helps<BR>mf<BR><BR><BR><BR><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