SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Mar 2007
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help making tables/formatting output in php

    Hi guys..

    I currently have a php file that will take information from my phpbb forum and post it on the main section of my joomla website. What I want it to do, works. I just can't get it to look the way I want it to.

    Here's the code:

    {
    echo "</a><li><strong>Forum</strong> <a href=\"".$urlPath."/viewforum.php?f=".$row['forum_id']."\">".$row["forum_name"]."</a><strong>
    Thread</strong> <a href=\"".$urlPath."/viewtopic.php?p=".$row['post_id']."#".$row['post_id']."\">".$row["topic_title"]."</a> by <a href=\"".$urlPath."/profile.php?mode=viewprofile&u=".$row['user_id']."\">".$row['username']."</li>";

    }
    it currently looks like this:



    as you see, I would like FORUM to be in one column, THREAD in another, and author in another column. Aligned to center.

    I was hoping to get something like this: it's in spanish but I guess you can get the idea.
    Mainly I would love to have the php output in columns, that's my main concern. But it would be nice to have the different kind of colors for each line. Like Dark gray, next light gray, etc.



    Well anyways.. If somebody knows how to do this and is willing to help me out, I'd very much appreciate it



  2. #2
    SitePoint Wizard bronze trophy C. Ankerstjerne's Avatar
    Join Date
    Jan 2004
    Location
    The Kingdom of Denmark
    Posts
    2,692
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    You are trying to use a list to show the subjects, where you should be using a table. You can use display:inline-block and then apply a width for each element, which is standard CSS, but it won't work in FireFox. Better to just use a table.
    Christian Ankerstjerne
    <p<strong<abbr/HTML/ 4 teh win</>
    <>In Soviet Russia, website codes you!

  3. #3
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That looks like a table to me, so it should be marked up as one.

    I suggest you learn how semantics apply to X/HTML. Semantics is really a very important subject when it comes to X/HTML.

    You can use display:inline-block and then apply a width for each element, which is standard CSS, but it won't work in FireFox.
    True. Firefox 2 does not support display:inline-block. Firefox 3 will though.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  4. #4
    SitePoint Wizard bronze trophy C. Ankerstjerne's Avatar
    Join Date
    Jan 2004
    Location
    The Kingdom of Denmark
    Posts
    2,692
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Kravvitz View Post
    True. Firefox 2 does not support display:inline-block. Firefox 3 will though.
    That's too bad. I usually throw this in the face of those people who can't stop talking about how superior FireFox is to Internet Explorer
    Christian Ankerstjerne
    <p<strong<abbr/HTML/ 4 teh win</>
    <>In Soviet Russia, website codes you!

  5. #5
    SitePoint Member
    Join Date
    Mar 2007
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi there again guys!
    I've updated the code so for and got the following results:


    PHP Code:
    echo "<table>";
    while(...)
    {
        echo 
    "<tr></a><td>
    <strong>Forum</strong> <a href=\""
    .$urlPath."/viewforum.php?f=".$row['forum_id']."\">".$row["forum_name"]."</td><td></a><strong>   
     Thread</strong> <a href=\""
    .$urlPath."/viewtopic.php?p=".$row['post_id']."#".$row['post_id']."\">".$row["topic_title"]."</td><td></a> by <a href=\"".$urlPath."/profile.php?mode=viewprofile&u=".$row['user_id']."\">".$row['username']."</td> </tr>";
    }
    echo 
    "</table>"




    since this is a loop. I would now like to make each line a different color, as the example I posted before.

    Putting html in php is tricking.. I can''t used numbers or anything since I get an error when executing the script.
    for example: I tried using a bg color for the tables and a fixed width. They always come up with an error that there is a missing ',' somewhere.

  6. #6
    SitePoint Wizard bronze trophy C. Ankerstjerne's Avatar
    Join Date
    Jan 2004
    Location
    The Kingdom of Denmark
    Posts
    2,692
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    Your HTML-syntax is wrong - you are ending the link after you have ended the table cell. The below code should do the trick.
    PHP Code:
    echo "<table>\n";
    $a 0;
    while(...) {
      if(
    $a&1) {
        
    $b "bbbbbb;";
      }
      else {
        
    $b "000000;";
      }
      echo 
    " <tr>\n";
      echo 
    "  <td style=\"background-color:#$b\"><strong>Forum:</strong> <a href=\"$urlPath/viewforum.php?f=$row['forum_id']\">$row['forum_name']</a></td>\n";
      echo 
    "  <td style=\"background-color:#$b\"><strong>Thread:</strong> <a href=\"$urlPath/viewtopic.php?p=$row['post_id']#$row['post_id']\">$row['topic_title']</a></td>\n";
      echo 
    "  <td style=\"background-color:#$b\">by <a href=\"$urlPath/profile.php?mode=viewprofile&u=$row['user_id']\">$row['username']</a></td>\n";
      echo 
    " </tr>\n";
      
    $a++;
    }
    echo 
    "</table>\n"
    You can replace the calues of $b with other colours, but it's better to replace that part of the code with a class.
    Christian Ankerstjerne
    <p<strong<abbr/HTML/ 4 teh win</>
    <>In Soviet Russia, website codes you!


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
  •