SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Location
    England
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Extracting Text FROM TEXT FIELD

    hi Guys/Gals,

    i am writing an articles page which may be divided into pages. Most of the time the article is only 1 page but may be more (2 or 3, 4 at a pinch ), but generally 1 or 2.

    I toyed with the idea of having a separate table, articlePages, to segment my pages, but thought that as the number of articles that would span over 1 page was low, the overhead was not worth it.

    Currently, i create the pages and insert a tag, [page], to identify a new page.

    I then use $pages = explode('[page]',$text) and then display content of page using $pages[$this->page];

    This is OK. But, i thought it could be done 'cleaner' if i could filter on the MYSQL end.

    My question is :-

    Is there a way, using reg exp or otherwise, to return a particular page straight from MYSQL?


    So if you had as your TEXT field

    'This is Page 1[page]This is Page 2[page]This is Page 3'

    to have a query to return the first, second or third segment depending on a parameter you passed?

    Regards SL

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,215
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    i suggest that you go ahead and implement your first idea -- articlePages

    the overhead is small compared to the difficulty of writing the sql to extract individual chunks out of one large field

    and the overhead is way smaller than pushing the entire field into php in order to "explode" it there, if you're not going to use all of it
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Location
    England
    Posts
    64
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks r2D2

    Yeah, got it working using RegExp but lol you right NOT worth it

    Nice and modularised first way anyhow.

    ThanKs anyroad

    SL


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
  •