SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Little Problem

  1. #1
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Little Problem

    if I have for example this code

    PHP Code:

    $query 
    "SELECT * FROM table ORDER BY date DESC";
    $result mysql_query(query);

    while (
    $row mysql_fetch_array($result) {

    $article $row['article'];
    $title $row['title'];

    echo 
    '<div id="content">';
    echo 
    "$title";
    echo 
    "$article";

    }

    ?> 
    Im not 100% sure if this question should be here, but becuase of my code the div id is set more than once and this make it unvalid html/xhtml.

    I want the code generated to be valid html/xhtml

    Is there a different way to do this to make it work.

  2. #2
    SitePoint Evangelist Aska's Avatar
    Join Date
    Aug 2003
    Location
    Melbourne, Australia
    Posts
    454
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Does the div need to have an ID? Can you achieve what you want to do with a class?
    PHP Code:
    echo '<div class="content">'

  3. #3
    SitePoint Member
    Join Date
    Sep 2004
    Location
    Internet
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It won't be valid either way. There is no end tag, i.e. </div>.

    By the way, if you can't get away with a class attribute, then you can try this:

    PHP Code:
    $suffix 1;

    while (
    $row mysql_fetch_array($result) { 

    $article $row['article']; 
    $title $row['title']; 

    echo 
    '<div id="content' .$suffix'">'
    echo 
    "$title"
    echo 
    "$article"

    $suffix++;


  4. #4
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    crap, there is an end tag in my code, I just forgot to type it above. sorry about that.

    I have tried what Iwant to do with a class but that wont work the way I want it to!

    Thanks

  5. #5
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Pythonic
    It won't be valid either way. There is no end tag, i.e. </div>.

    By the way, if you can't get away with a class attribute, then you can try this:

    PHP Code:
    $suffix 1;

    while (
    $row mysql_fetch_array($result) { 

    $article $row['article']; 
    $title $row['title']; 

    echo 
    '<div id="content' .$suffix'">'
    echo 
    "$title"
    echo 
    "$article"

    $suffix++;

    Thanks a lot for that pythonic.

    I guess i just need to add the potential entries with the suffix number into my css file.


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
  •