SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    BoOm-Rocka! Smarky's Avatar
    Join Date
    Jun 2000
    Location
    England
    Posts
    1,319
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Splitting up a one field and out putting in separate table rows

    Righty, I have a field in a mysql database that contains some links, I need these links to be formatted in html on a separate row in a table although they are contained in the db as one.

    output something like this

    <tr> link one </tr>
    <tr> link two </tr> etc..

    It is stored in the DB in plain HTML with a <BR> tag between the links.

    For example

    <a href="link1"> link one </a> <br> <a href="link2"> Link two </a>.

    So the <br> tags need to be striped, I guess this is what could be used to strip the data one by one, just need to know how to do this. Thanks
    Garlic bread, I've tasted it, it's the future

  2. #2
    SitePoint Addict The Mog's Avatar
    Join Date
    Dec 2002
    Location
    Manchester UK
    Posts
    310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here you go,

    just use explode

    PHP Code:
    <?php
    // Below is your query
    $links "<a href=\"link1\"> link one </a> <br> <a href=\"link2\"> Link two </a>";
    // Split them
    $links=explode("<br>",$links);
    // Print out the table
    print "<table width=\"20%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
    for(
    $i=0;$i<count($links);$i++){
          print 
    "<tr><td>".$links[$i]."</td></tr>";
          }
     print  
    "</table>";

    ?>


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
  •