Avatar billede guzzie Nybegynder
29. januar 2001 - 13:53 Der er 14 kommentarer og
1 løsning

select distinct colume from database

hey there

have 2 asp pages
the first is a form that send that value to the next page
However I would like the value to be a distinct colume and not row from the database
something like this

strSQL = \"SELECT FROM abc(\" & request(\"alpha\") & \"\') ORDER BY ID ASC ;\"

alpha should be the value of the colume name sent by my form

any ideas
thanks
Guzzie
Avatar billede eagleeye Praktikant
29. januar 2001 - 13:58 #1
strSQL = \"SELECT FROM abc(\" & request.form(\"alpha\") & \"\') ORDER BY ID ASC ;\"
Avatar billede eagleeye Praktikant
29. januar 2001 - 14:01 #2
Form POST method:
strSQL = \"SELECT FROM abc(\" & request.form(\"alpha\") & \"\') ORDER BY ID ASC ;\"

Form GET method:
strSQL = \"SELECT FROM abc(\" & request.QueryString(\"alpha\") & \"\') ORDER BY ID ASC ;\"
Avatar billede guzzie Nybegynder
29. januar 2001 - 14:17 #3
hey there

I tried your idea but the page wouldn`t display
I dont get any error message
I think my loop is incorrect,
Im not that advanced in ASP :) as you can see

this is how my form looks

<form method=\"POST\" action=\"wordinfo.asp\">
<select name=\"alpha\">
<option selected>-Choose-</option>
<option value=\"a\">a</option>
<option value=\"b\">b</option>
<option value=\"c\">c</option>
<option value=\"d\">d</option>
<option value=\"e\">e</option>
<option value=\"f\">f</option>
<option value=\"g\">g</option>
<option value=\"h\">h</option>
<option value=\"i\">i</option>
<option value=\"j\">j</option>
<option value=\"k\">k</option>
<option value=\"l\">l</option>
<option value=\"m\">m</option>
<option value=\"n\">n</option>
<option value=\"o\">o</option>
<option value=\"p\">p</option>
<option value=\"q\">q</option>
<option value=\"r\">r</option>
<option value=\"s\">s</option>
<option value=\"t\">t</option>
<option value=\"u\">u</option>
<option value=\"v\">v</option>
<option value=\"w\">w</option>
<option value=\"x\">x</option>
<option value=\"y\">y</option>
<option value=\"z\">z</option>
</select>
<input type=\"submit\" value=\"Search\" name=\"Action\">
</form>


and the page its displayed on like this

<html>


<body>

<% Response.Buffer = True

    intPage = Request(\"page\")
    If isNumeric(intPage) = False Or intPage < 1 Then
      intPage = 1
    End If
    Set rs = Server.CreateObject(\"ADODB.RecordSet\")
    strSQL = \"SELECT FROM abc(\" & request.form(\"alpha\") & \"\') ORDER BY ID ASC ;\"
    strDSN = \"DRIVER={Microsoft Access Driver (*.mdb)};DBQ=\"&Server.MapPath(\"popup.mdb\")
    rs.Open strSQL, strDSN, 1
    If Not (rs.BOF Or rs.EOF) Then
      rs.PageSize = 5
      rs.AbsolutePage = intPage
      intRecCount = rs.PageSize
      intPageCount = rs.PageCount


%>

<table width=\"300\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\">
  <tr>

<%
  Do While Not rs.EOF And intRecCount > 0
%>

    <td><% Response.Write rs(\" & request.form(\"alpha\") & \") %></td>
</tr>

<%
  intRecCount = intRecCount - 1
  rs.MoveNext
  Loop
End If
rs.Close
Set rs = Nothing
%>

</table>
<br>
<div align=\"center\">
<%
If Clng(intPage) > Clng(intRecCount) Then
%>
<a href=\"wordinfo.asp?page=<%=intPage - 1%>\">&lt;&lt;&nbsp;Last 20</a>
<%
Else
%>
&lt;&lt;&nbsp;Last 20
<%
End If
%>
&nbsp; - &nbsp;
<%
If Clng(intPage) < Clng(intPageCount) Then
%>
<a href=\"wordinfo.asp?page=<%=intPage + 1%>\">Next 20 &gt;&gt;</a>
<%
Else
%>
Next 20 &gt;&gt;
<%
End If
%>
</div>
</body>
</html>
Avatar billede strax Nybegynder
29. januar 2001 - 14:24 #4
You are missing a hyphen from the line:

strSQL = \"SELECT FROM abc(\" & request.QueryString(\"alpha\") & \"\') ORDER BY ID ASC ;\"

strSQL = \"SELECT FROM abc(\'\" & request.QueryString(\"alpha\") & \"\') ORDER BY ID ASC ;\"

and do a little error finding:

<%
  intRecCount = intRecCount - 1
  rs.MoveNext
  Loop
End If
rs.Close
Set rs = Nothing
%>

Should be:
<%
  intRecCount = intRecCount - 1
  rs.MoveNext
  Loop
-> else
    Response.Write(\"The Recordset is empty\")
  End If
rs.Close
Set rs = Nothing
%>



Avatar billede eagleeye Praktikant
29. januar 2001 - 14:31 #5
You need to correct your SQL statment:

What is \"abc\" a Table name or Field name ?   

SELECT column-name(s) FROM tablename WHERE column-name=value

SELECT * FROM abc WHERE ?!?!=&Request.Form(\"alpha\")

a * means all columns witin the table.
Avatar billede guzzie Nybegynder
29. januar 2001 - 14:39 #6
hey again

popup is the database
abc is my table name
I would the the value of alpha to be the name of the choosen colume

I have columes in my table called a,b,c,d......
so that if \"a\" is choosen then only \"a\" colume is shown and looped on the next page

More points now 50 :)
thanks guys
Avatar billede strax Nybegynder
29. januar 2001 - 14:43 #7
sqlstr = \"select \" & Request.Form(\"alpha\") & \" from abc\"
Avatar billede guzzie Nybegynder
29. januar 2001 - 14:57 #8
hey there again guys
sorry I cant seem to work it out
heres 100 points to the first one to work it out
as i have looked at it to long and cant make head or tail of it ;(

\"default.asp\"

<form method=\"POST\" action=\"wordinfo.asp\">
<select name=\"alpha\">
<option selected>-Choose-</option>
<option value=\"a\">a</option>
<option value=\"b\">b</option>
<option value=\"c\">c</option>
<option value=\"d\">d</option>
<option value=\"e\">e</option>
<option value=\"f\">f</option>
</select>
<input type=\"submit\" value=\"Search\" name=\"Action\">
</form>

\"wordinfo.asp\"

<html>


<body>

<% Response.Buffer = True

    intPage = Request(\"page\")
    If isNumeric(intPage) = False Or intPage < 1 Then
      intPage = 1
    End If
    Set rs = Server.CreateObject(\"ADODB.RecordSet\")
    sqlstr = \"select \" & Request.Form(\"alpha\") & \" from abc\"
   
    strDSN = \"DRIVER={Microsoft Access Driver (*.mdb)};DBQ=\"&Server.MapPath(\"popup.mdb\")
    rs.Open strSQL, strDSN, 1
    If Not (rs.BOF Or rs.EOF) Then
      rs.PageSize = 5
      rs.AbsolutePage = intPage
      intRecCount = rs.PageSize
      intPageCount = rs.PageCount


%>

<table width=\"300\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\">
  <tr>

<%
  Do While Not rs.EOF And intRecCount > 0
%>

    <td><% rs(\'\" & request.form(\"alpha\") & \"\') %></td>
</tr>

<%
  intRecCount = intRecCount - 1
  rs.MoveNext
  Loop
else
    Response.Write(\"The Recordset is empty\")
  End If
rs.Close
Set rs = Nothing
%>





</table>
<br>
<div align=\"center\">
<%
If Clng(intPage) > Clng(intRecCount) Then
%>
<a href=\"wordinfo.asp?page=<%=intPage - 1%>\">&lt;&lt;&nbsp;Last 5</a>
<%
Else
%>
&lt;&lt;&nbsp;Last 5
<%
End If
%>
&nbsp; - &nbsp;
<%
If Clng(intPage) < Clng(intPageCount) Then
%>
<a href=\"wordinfo.asp?page=<%=intPage + 1%>\">Next 5 &gt;&gt;</a>
<%
Else
%>
Next 5 &gt;&gt;
<%
End If
%>
</div>
</body>
</html>


My database has a the following columes
Id
a
b
c
d
e
f


hope the points and info help
thanks for the help and time
Guzzie(Big time ASP nubie)
Avatar billede strax Nybegynder
29. januar 2001 - 15:14 #9
Dont\'t wanna do all that, sorry

> If Not (rs.BOF Or rs.EOF) Then

This line should read

> If Not (rs.BOF AND rs.EOF) Then

as this is true if your recordset is empty
Avatar billede strax Nybegynder
29. januar 2001 - 15:15 #10
Before ... you skipped your whole loop, because you always got a true from the rs.BOF statement
Avatar billede guzzie Nybegynder
29. januar 2001 - 15:41 #11
hey there strax

I have done the script just as a normal database connection and changed what you said
I am leaving out the \"next\" funchion :( till another time when i know more what i am doing :)

I have know tried but it still will not show anything
<html>
<body>
<%

Set Conn = Server.CreateObject(\"ADODB.Connection\")
Conn.Open \"DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=\" & server.MapPath(\"popup.mdb\")
sqlstr = \"select \" & Request.Form(\"alpha\") & \" from abc\" 

Conn.Execute (strSQL)

Set rs = conn.Execute(strSQL)
if not (rs.BOF and rs.EOF) Then
%>
<table class=\"border\" width=\"300\" align=\"center\" valign=\"top\" cellpadding=\"5\" cellspacing=\"0\" border=\"0\">
<tr>
    <td class=\"one\"><table>
<% Do While Not rs.EOF %>
<tr>
    <td><%=rs\"(\" & Request.Form(\"alpha\") & \")\"%></td>
</tr>
<%
RS.MoveNext
Loop
%>
</table>
</td>
</tr>
</table>
<%
conn.Close
Set conn = nothing
%>

<% else %>

<%
response.redirect (\"default.asp\")
%>

</body>
</html>
<% end if %>

Guzzie ;(
Avatar billede strax Nybegynder
29. januar 2001 - 15:52 #12
The line where you make output doesn\'t make sense

<td><%=rs\"(\" & Request.Form(\"alpha\") & \")\"%></td>


Put this instead
<td><% =rs(0) %> = Result</td>

This way you are showing the first result from the først row, and some text, in case the result is empty.

I think the problem is that you were creating something like

<Table><td><td><td><td></table>

which doesn\'t produce any output
Avatar billede guzzie Nybegynder
30. januar 2001 - 20:06 #13
sorry but the script is still not working at all :)
Avatar billede eagleeye Praktikant
30. januar 2001 - 20:53 #14
<html>
<body>

<%
Set Conn = Server.CreateObject(\"ADODB.Connection\")
Set rs = Server.CreateObject (\"ADODB.RecordSet\")

Conn.Open \"DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=\" & server.MapPath(\"popup.mdb\")

strSQL = \"select \" & Request.Form(\"alpha\") & \" from abc\"

Set rs = conn.Execute(strSQL)

if not (rs.BOF and rs.EOF) Then
%>

<table class=\"border\" width=\"300\" align=\"center\" valign=\"top\" cellpadding=\"5\" cellspacing=\"0\" border=\"0\">
<tr><td class=\"one\"><table>
<%
Do While Not rs.EOF
%>
<tr>
<td>
<%=rs(0)%>
</td></tr>
<%
RS.MoveNext
Loop
%>
</table> </td></tr></table>
<%
conn.Close
Set conn = nothing
%>
<% else %>

<%
response.redirect (\"default.asp\")
%>
<% end if %>

</body>
</html>
Avatar billede guzzie Nybegynder
30. januar 2001 - 21:07 #15
hey thank you :)

that works like a dream :)
I still cant see want was wrong but now it works so I can go thru it and see for myself

Many thanks :)
Guzzie
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester