Closed Thread Icon

Topic awaiting preservation: asp and sql using "like" Pages that link to <a href="https://ozoneasylum.com/backlink?for=26449" title="Pages that link to Topic awaiting preservation: asp and sql using &amp;quot;like&amp;quot;" rel="nofollow" >Topic awaiting preservation: asp and sql using &quot;like&quot;\

 
Author Thread
slim___shady
Nervous Wreck (II) Inmate

From: canada
Insane since: Aug 2002

posted posted 08-15-2005 05:46

I'm trying to display data from a table that starts with whatever letter the user clicked on.

I have letters a to z as links. When a user clicks on a letter, I would like data from the table that starts with that letter, to be displayed. My code has an error in the Select statement - set rs=con.execute("select * from players where yahoosn like "&'letter%'&" order by yahoosn"). Can someone please help me fix that? The table has just 2 columns - yahoosn and a picPath

<html></head>
<body>
<%
letter=request.querystring("letter")
'response.write letter'
set con=server.createObject("adodb.connection")
con.open "provider=microsoft.jet.oledb.4.0;data source=" & Server.MapPath("db/ufp.mdb")
set rs=con.execute("select * from players where yahoosn like "&'letter%'&" order by yahoosn")
%>

<p>
<a href="players.asp?letter=a">a</a> |
<a href="players.asp?letter=b">b</a> |
<a href="players.asp?letter=c">c</a> |
<a href="players.asp?letter=d">d</a> |
<a href="players.asp?letter=e">e</a> |
<a href="players.asp?letter=f">f</a> |
<a href="players.asp?letter=g">g</a> |
<a href="players.asp?letter=h">h</a> |
<a href="players.asp?letter=i">i</a> |
<a href="players.asp?letter=j">j</a> |
<a href="players.asp?letter=k">k</a> |
<a href="players.asp?letter=l">l</a> |
<a href="players.asp?letter=m">m</a> |
<a href="players.asp?letter=n">n</a> |
<a href="players.asp?letter=o">o</a> |
<a href="players.asp?letter=p">p</a> |
<a href="players.asp?letter=q">q</a> |
<a href="players.asp?letter=r">r</a> |
<a href="players.asp?letter=s">s</a> |
<a href="players.asp?letter=t">t</a> |
<a href="players.asp?letter=u">u</a> |
<a href="players.asp?letter=v">v</a> |
<a href="players.asp?letter=w">w</a> |
<a href="players.asp?letter=x">x</a> |
<a href="players.asp?letter=y">y</a> |
<a href="players.asp?letter=z">z</a>
</p>
<%
while not rs.eof
response.write rs("yahoosn")
rs.movenext
wend
%>
</body></html>

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 08-15-2005 09:57

you'll need to add quotes to the 'string within sql'.
it should read more like

set rs=con.execute("select * from players where yahoosn like '" & "letter%" & "' order by yahoosn")


(note: Stickt to one kind of quotes when conconating strings, and spaces around operators are usually agood idea)

so long,

->Tyberius Prime

« BackwardsOnwards »

Show Forum Drop Down Menu