Results 1 to 2 of 2

Thread: displaying paragraph vs list items from a database

  1. #1
    Join Date
    Oct 2007
    Posts
    103

    displaying paragraph vs list items from a database

    Hi,
    New to php and mysql but I got a question:

    Lets say I am creating a database table with coulmns like in below for a news portal website:

    story title
    first paragraph
    second paragraph
    third paragraph
    ...
    ...
    contact info

    I would want the title display in some format and paragraphs in another format and the contact info another etc...

    My question is:

    If lets say there needs to be a list item in between two paragraphs (but this wont be the case always), can I insert that list within the paragraph text in the database within the paragraph such as
    <ul>
    <li>...</li>
    <li>...</li>
    </ul>
    , and it will display as a list in the website? Or do I need to have a seperate column in the table for a listed item? But the location and size of list item (if any) will be different for each article. So I thought I should not make a column for listed items, but insert in one of the paragraph columns. So the question is will it display correctly and how can I do that?



    Thanks

  2. #2
    Join Date
    Feb 2008
    Posts
    85
    There is a problem with your table design. If each paragraph needs its own column, then what happens when your article has one more paragraph than you have columns?

    An alternative would be:

    ArticleID
    ParagraphNumber
    Paragraph

    So records might look like this:

    Code:
    ArticleID    ParagraphNumber   Paragraph
    1              1                        This is the first paragraph
    1              2                        This is the second paragraph
    1              3                        This is the third paragraph
    Then to pull the data out:

    Code:
       select Paragraph from article where ArticleID = $article order by ParagraphNumber asc
    This will return an array with $article's paragraphs in the right order, and then you can loop through the array and display them however your site needs.
    ServWise Advanced Hosting - Better, Faster, Smarter

Similar Threads

  1. Creating multiple dynamic list boxes from mysql database
    By phoenix211984 in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 0
    Last Post: 26 Sep 2006, 07:26 PM
  2. Ordered List Question
    By Gage8 in forum Web Design, HTML Reference and CSS
    Replies: 1
    Last Post: 16 Dec 2005, 02:16 PM

Posting Permissions

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