1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

table formatting help!

Discussion in 'PHP' started by Funk-woo10, Apr 8, 2008.

  1. #1
    Hi all,

    When i echo the results they come out in a list, for example -

    a
    a
    a
    a
    a

    How can i get them to display like this -

    a a
    a a
    a a


    basicly i want results in a two column table !
     
    Funk-woo10, Apr 8, 2008 IP
  2. jayshah

    jayshah Peon

    Messages:
    1,126
    Likes Received:
    68
    Best Answers:
    1
    Trophy Points:
    0
    #2
    You will need to:

    Table tag and initial row (<table><tr>)
    Set a $counter = 0;

    For every output, output "<td>{$output}</td>";
    Add $counter + 1;

    For every "even" counter output "</tr><tr>";
    Check using:

    
    if (($counter % 2) == 0){
        echo "</tr><tr>";
    }
    
    PHP:
    I hope this gives the general idea of how it can be accomplished.

    Jay
     
    jayshah, Apr 8, 2008 IP
  3. Funk-woo10

    Funk-woo10 Peon

    Messages:
    1,109
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #3
    how would i work that into this -

    
    mysql_select_db("****_****", $con);
    echo "<table border='1'>";
    
    $result = mysql_query("SELECT ***** blah***** Limit 6");
    
    
    
    while($row = mysql_fetch_array($result))
      {
        echo "<tr><td>";
       echo "<img src='http://www.****/images/***/";
     echo $row['m_id'];
    echo "-";
     echo $row['i_id'];
     echo ".jpg' />";
      echo "</td></tr>";
      }mysql_close($con);
    echo "</table>";
    ?>
    
    
    PHP:

    do you have any good tutorials on this ? i have googled to much
     
    Funk-woo10, Apr 8, 2008 IP
  4. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #4
    Try this one

    mysql_select_db("****_****", $con);
    echo "<table border='1'>";
    
    $result = mysql_query("SELECT ***** blah***** Limit 6");
    
    $counter = 0;
    
    while($row = mysql_fetch_array($result)) {
      
        if($counter == 2) {
         $counter = 0;
       }
    
        if ($counter  ==  0){
         echo "<tr>";
        }
     
        echo "<td>";
        echo "<img src='http://www.****/images/***/";
        echo $row['m_id'];
        echo "-";
        echo $row['i_id'];
        echo ".jpg' />";
        echo "</td>";
    
     if ($counter == 1){
         echo "</tr>";
        }
    
      $counter++;
     }
    
    mysql_close($con);
    echo "</table>";
    ?>
    PHP:
     
    stephan2307, Apr 8, 2008 IP
    Funk-woo10 likes this.
  5. Funk-woo10

    Funk-woo10 Peon

    Messages:
    1,109
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #5
    great that works ! thanks !
     
    Funk-woo10, Apr 8, 2008 IP