By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,939 Members | 1,638 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,939 IT Pros & Developers. It's quick & easy.

Drawing meta tags from a database in an asp page

100+
P: 114
I want to draw out records from the database, and use them in my meta tags. I only want to use one record, which is called "TITLE", and i want to use this in the "title", "keywords", and "description", in other word the content of all 3 is "TITLE"

I have page called "view.asp" whose relevant code is as below. The meta tags are in "inc.header.asp" file.


Expand|Select|Wrap|Line Numbers
  1. <!--#include file="inc_header.asp"--> 
  2.  
  3.     <% Dim SQL, RS, ID, TITLE, CONTENT, SUMMARY, POSTED, ALLOW_C, ALLOW_V, UPDATED, MESSAGE, VOTED, ALLOW_V_MAIN, _
  4.            ALLOW_C_MAIN, NID, AUTHOR, CATEGORIES, AID, USE_VIEW, NIMAGE
  5.           Dim CCOUNT, C_ID, C_NAME, C_EMAIL, C_COMMENT, C_DATE, C_SUBJECT, C_M_ID, C_ALLOW_E, C_CITY, C_COUNTRY, _
  6.               RCOUNT, RID, RTITLE, ACOUNT
  7.  
  8.  
  9.     NID   = Trim(Request.QueryString("ID"))
  10.     VOTED = Trim(Request.Cookies("NEWS_ARTICLE_" & NID))    
  11.     MEMBER_ID = Trim(Session("PMMS_ID"))    
  12.     IF Trim(Session("PMMS_IN")) = "True" THEN blLOGGED_IN = True    
  13.  
  14.     IF IS_VALID_ID(NID) THEN
  15.  
  16.         Call OPEN_DB() 
  17.  
  18.         SQL = "SELECT fldA_V, fldA_C FROM nm_tbl_settings WHERE ID = 1"
  19.         Set RS = Server.CreateObject("ADODB.Recordset")
  20.         RS.LockType   = 1
  21.         RS.CursorType = 0
  22.         RS.Open SQL, MyConn    
  23.              IF NOT RS.EOF THEN
  24.                  ALLOW_V_MAIN = trim(RS("fldA_V"))
  25.                 ALLOW_C_MAIN = trim(RS("fldA_C"))
  26.              END IF
  27.         RS.Close        
  28.  
  29.         SQL = "UPDATE nm_tbl_news SET fldVIEWS = fldVIEWS + 1 WHERE ID = " & NID
  30.         MyConn.Execute(SQL)
  31.  
  32.         SQL = "SELECT fldTITLE, fldCONTENT, fldSUMMARY, nm_tbl_news.fldACTIVE AS ACTIVE, fldAID, fldPOSTED, fldEXPIRES, nm_tbl_news.fldIMAGE AS NIMAGE, fldALLOW_COMMENTS, fldALLOW_VOTING, fldCREATED, fldUPDATE, nm_tbl_agent.fldNAME AS ANAME, nm_tbl_news.fldAID AS AID, fldUSE_VIEW FROM nm_tbl_news, nm_tbl_agent WHERE (nm_tbl_agent.ID = nm_tbl_news.fldAID) AND (nm_tbl_news.fldACTIVE = 1) AND nm_tbl_news.ID = " & NID ' { AND (Now() - {GetDate()} BETWEEN fldPOSTED AND fldEXPIRES)) }
  33.         response.write vbNewLine & "<!-- SQL: " & SQL & " -->" & vbNewLine
  34.         Set RS = Server.CreateObject("ADODB.Recordset")
  35.         RS.LockType   = 1
  36.         RS.CursorType = 0
  37.         RS.Open SQL, MyConn    
  38.              IF NOT RS.EOF THEN
  39.                  TITLE   = trim(RS("fldTITLE"))
  40.                 CONTENT = trim(RS("fldCONTENT"))
  41.                 SUMMARY = trim(RS("fldSUMMARY"))
  42.                 POSTED  = trim(RS("fldPOSTED"))
  43.                 ALLOW_C = trim(RS("fldALLOW_COMMENTS"))
  44.                 ALLOW_V = trim(RS("fldALLOW_VOTING"))
  45.                 UPDATED = trim(RS("fldUPDATE"))
  46.                 AUTHOR  = trim(RS("ANAME"))
  47.                 AID     = trim(RS("AID"))
  48.                 USE_VIEW= trim(RS("fldUSE_VIEW"))
  49.                 NIMAGE  = trim(RS("NIMAGE"))                
  50.              ELSE   
  51.                 MESSAGE = MESSAGE & "<li />This article is currently not available."
  52.              END IF
  53.              response.write vbNewLine & "<!-- SQL: " & SQL & " -->" & vbNewLine
  54.         RS.Close 
  55.  
  56.         CONTENT = ReplaceAuthorTokens(AID, CONTENT)        
  57.         CATEGORIES = GET_CATES(NID)
  58.  
  59.         ' Get settings
  60.         Dim DATE_F
  61.         DATE_F = GET_SETTINGS(False, "fldDATE_F")        
  62.  
  63.         TITLE = PROCESS_SHORTCUTS(False, TITLE)
  64.         CONTENT = PROCESS_SHORTCUTS(False, CONTENT)
  65.         SUMMARY = PROCESS_SHORTCUTS(False, SUMMARY)
  66.  
  67.     ELSE
  68.  
  69.       MESSAGE = MESSAGE & "<li />No article has been found."
  70.  
  71.     END IF
  72.     %>
and this is the relevant part of the "inc.header.asp" code below

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. <!--#include file="config.asp"-->
  4. <!--#include file="inc_api.asp"-->
  5. <% Response.Buffer = True %>
  6.  
  7. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  8. <html>
  9. <head> 
  10. <% 
  11. title = "article title" %>
  12. <title> rs("TITLE")</title>
  13. <%
  14. meta_description = "the description goes here" %>
  15. <meta name="description" content="rs("fldTITLE")">
  16. <%
  17. meta_keywords = "this, is, the, keyword, section," %> 
  18. <meta name="keywords" content="RS("fldTITLE")">
However, the above code doesn't pull out the field "title" and display it, when i check the page on the world wide web. When i check the code using "view source" this is what it says:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head> 
  3.  
  4. <title> rs("TITLE")</title>
  5.  
  6. <meta name="description" content="rs("fldTITLE")">
  7.  
  8. <meta name="keywords" content="RS("fldTITLE")">
So what am i doing wrong? i think i have the code in the "inc.header.asp" messed up somewhere. ~Any help appreciated.
Oct 8 '07 #1
Share this Question
Share on Google+
4 Replies


100+
P: 114
Sorry i forgot to add, I'm not html literate, so i'd appreciate it if anyone could show me exactly what to put on both pages
Oct 8 '07 #2

100+
P: 114
actually i've changed the format now, i no longer need the inc.header.asp page,

so i'm going to put the code at the top of the view.asp page, which is like this, however, it's not picking up the Title. I want the title of the article to be the title of the page, and the meta tags content for description and keywords. The code is as above, so where do i put the

the code to view.asp is in the first post i posted in this thread


Expand|Select|Wrap|Line Numbers
  1. <% 
  2. title = "article title" %>
  3. <title><%=title%></title>
  4. <%
  5. meta_description = "the description goes here" %>
  6. <meta name="description" content="<%=meta_description%>">
  7. <%
  8. meta_keywords = "this, is, the, keyword, section," %> 
  9. <meta name="keywords" content="<%=meta_keywords%>">
Oct 8 '07 #3

jhardman
Expert 2.5K+
P: 3,405
Sorry i forgot to add, I'm not html literate, so i'd appreciate it if anyone could show me exactly what to put on both pages
There are some good ways to become HTML literate. It is generally considered an easy-to-learn language. It really isn't a programming language, it is just plain text instruction for how to format text and display web pages. Here is a good tutorial. If you are planning to do all the work of building and maintaining the site, it might be a good idea to find a good reference book. Most public libraries have a few, and every bookstore and computer supply store has several to chose from.

Jared
Oct 9 '07 #4

100+
P: 114
I will try that, Jared, thanks for the tips.
Oct 11 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.