unplugged_web Posted November 17, 2010 Share Posted November 17, 2010 I wonder if somebody could help me please. I'm trying to limit the number of characters of the 'title' field to 20 but I'm not sure how to do this. This is what I've got, but I don't know how to do this <%response.ContentType = "text/xml"set conn=Server.CreateObject("ADODB.Connection")conn.Provider="Microsoft.Jet.OLEDB.4.0;"conn.open Server.MapPath("/database/database.mdb")sql="select top 10 * from listings where active <> 0 order by idate desc"set rs=Conn.Execute(sql) Thanks for your help Link to comment Share on other sites More sharing options...
justsomeguy Posted November 17, 2010 Share Posted November 17, 2010 I don't see where the "title" field is, but you use a VBScript function like left to return the left part of a string. Link to comment Share on other sites More sharing options...
unplugged_web Posted November 17, 2010 Author Share Posted November 17, 2010 I don't see where the "title" field is, but you use a VBScript function like left to return the left part of a string.I tried that and it didn't seem to work - it just said missing label. This is what I tried:[code}<%response.ContentType = "text/xml"set conn=Server.CreateObject("ADODB.Connection")conn.Provider="Microsoft.Jet.OLEDB.4.0;"conn.open Server.MapPath("/database/database.mdb")sql="select top 10 * from listings where active <> 0 order by idate desc"title=Left(UserName, 20)set rs=Conn.Execute(sql)response.write("<?xml version='1.0' encoding='UTF-8'?>")response.write("<wapl xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:noNamespaceSchemaLocation='http://wapl.wapple.tv/wapl.xsd'>")response.Write("<head>")response.write("<title>The Mobi Store</title>")response.Write("</head>")response.write("<layout>")while (not rs.EOF)response.write("<row>")response.write("<cell class='darkLink'>")response.write("<link>")response.write("<url>http://www.domain.tv/mobile/code/details.asp</url>")response.write("<label>" &title& "</label>")response.write("<linkVars>")response.write("<var>")response.write("<name>details</name>")response.write("<value>" & rs("id") & "</value>")response.write("</var>")response.write("</linkVars>")response.write("</link>")response.write("</cell>")response.write("</row>")rs.MoveNext()wendrs.close()conn.close()response.write("</layout>")response.write("</wapl>")%>[/code] Link to comment Share on other sites More sharing options...
justsomeguy Posted November 17, 2010 Share Posted November 17, 2010 title=Left(UserName, 20)Where is UserName defined? This is not SQL code, this is VB code. You need to use the function on a VB variable. You probably need to use it on one of the fields in the rs object. Link to comment Share on other sites More sharing options...
unplugged_web Posted November 18, 2010 Author Share Posted November 18, 2010 Where is UserName defined? This is not SQL code, this is VB code. You need to use the function on a VB variable. You probably need to use it on one of the fields in the rs object.sorry I'm completely lost then, I've never used asp before and haven't got a clue where to start with it Link to comment Share on other sites More sharing options...
justsomeguy Posted November 18, 2010 Share Posted November 18, 2010 All you're trying to do is show the left part of the value. The value isn't in an undefined variable, it's in the rs object. You're getting a value right here:response.write("<value>" & rs("id") & "</value>")Just add the left function to that. Link to comment Share on other sites More sharing options...
unplugged_web Posted November 19, 2010 Author Share Posted November 19, 2010 All you're trying to do is show the left part of the value. The value isn't in an undefined variable, it's in the rs object. You're getting a value right here:response.write("<value>" & rs("id") & "</value>")Just add the left function to that.I added the line here:response.write("<label>" & rs(Left("title",20)) & "</label>")but it didn't work - it still showed the same number of characters regardless of what the number was. Unless I set it to 2 then it showed nothing at all. Link to comment Share on other sites More sharing options...
justsomeguy Posted November 19, 2010 Share Posted November 19, 2010 Your thought process is definitely unique. The value is rs("title"), that's the name of the value. You've split that up, so you have the rs first, then inside of that you have the left function acting on the value "title". This:Left("title",20)Is going to take the first 20 characters of the string "title". Since that string only has 5, it's always going to return the string "title", so it's the exact same thing as just doing rs("title"). You don't want to change the name of the field you're trying to get, you want to change the value of it. Like I said, the value of the field is rs("title"). So you want to take the first 20 characters of rs("title"):Left(rs("title"), 20) Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.