SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot trigger8's Avatar
    Join Date
    Nov 2000
    Location
    Dallas, TX
    Posts
    133
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Page break in ASP

    I have one text field in MSSQL that holds the entire text article, and I would like a stored procedure or a function to break the article into pages based on the character limit per page. However, I don't want it to break into the middle of a word.
    I can then use NEXT/PREVIOUS to navigate the pages.

    Any ideas?
    Last edited by trigger8; Sep 24, 2002 at 11:17.
    Trigger8

    **************************
    I killed a 6-pack just to watch it die!

  2. #2
    morphine for a wooden leg randem's Avatar
    Join Date
    Jun 2002
    Location
    .chicago.il.us
    Posts
    957
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just write up a simple function that searches ahead the given number of spaces, and then backs off one character at a time until a space or hyphen is found.
    ----Adopt-a-Sig----
    Your message here!

  3. #3
    SitePoint Zealot trigger8's Avatar
    Join Date
    Nov 2000
    Location
    Dallas, TX
    Posts
    133
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I understand how to create a character limit function but have no idea about a reverse lookup.
    Can you help?
    Trigger8

    **************************
    I killed a 6-pack just to watch it die!

  4. #4
    SitePoint Zealot trigger8's Avatar
    Join Date
    Nov 2000
    Location
    Dallas, TX
    Posts
    133
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My current stored procedure uses character limit to break text into pages based on parameters. However, it will break into the word. Can anybody help?

    Code:
    CREATE PROCEDURE _GETBodytest
    	@ID INT,
    	@MAXTEXTLENHEADLINE INT, --Headline is truncated at this qty of chars & ... is appended if needed
    	@MAXTEXTLENBODY INT      --Body is broken up into multiple rows
    
    AS
    
    SET NOCOUNT ON
    
    DECLARE @HEADLINE AS VARCHAR(2000) --Can't use a variable here, ugh!
    DECLARE @BODYLEN INT
    DECLARE @QTYROWS INT
    DECLARE @CURROW INT
    
    --Grab headline
    SET @HEADLINE = (SELECT 
    	Headline = 
    		CASE 
    			WHEN LEN(RawTitle) <= @MAXTEXTLENHEADLINE THEN RawTitle
    			WHEN LEN(RawTitle) > @MAXTEXTLENHEADLINE THEN SUBSTRING(RawTitle, 1, @MAXTEXTLENHEADLINE) + '...'
    		END
    FROM Content
    WHERE ContentID = @ID
    )
    
    --Grab length of body text
    SELECT @BODYLEN = LEN(RawBody) FROM Content WHERE ContentID = @ID
    SET @QTYROWS = @BODYLEN / @MAXTEXTLENBODY
    IF @BODYLEN % @MAXTEXTLENBODY > 0 SET @QTYROWS = @QTYROWS + 1
    
    SET @CURROW = 0
    
    --Put in primer row
    SELECT @HEADLINE AS Headline, @QTYROWS AS QtyRows, 0 AS RowNum, 
    	Body = 
    		CASE 
    			WHEN LEN(RawBody) <= @MAXTEXTLENBODY THEN RawBody
    			WHEN LEN(RawBody) > @MAXTEXTLENBODY THEN SUBSTRING(RawBody, 1, @MAXTEXTLENBODY) + '...'
    		END
    INTO #Temp
    FROM Content WHERE ContentID = @ID
    
    --Now that table is made, clear
    DELETE FROM #Temp
    
    WHILE @CURROW < @QTYROWS
    BEGIN
    	INSERT INTO #Temp SELECT @HEADLINE, @QTYROWS, @CURROW + 1, SUBSTRING(RawBody, 1 + (@CURROW * @MAXTEXTLENBODY), @MAXTEXTLENBODY) FROM Content WHERE ContentID = @ID
    	SET @CURROW = @CURROW + 1
    END
    
    UPDATE #Temp SET Body = Body + '...' WHERE RowNum < QtyRows
    
    SELECT * FROM #Temp ORDER BY RowNum
    GO
    Last edited by trigger8; Sep 24, 2002 at 12:15.
    Trigger8

    **************************
    I killed a 6-pack just to watch it die!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •