mysql php layout problem

Discussion in 'PHP' started by white10, Jun 20, 2007.

  1. #1
    Hi guys

    I got this problem, at the moment the code below:

    while ($cats = mysql_fetch_array($get_cats_res)) {
    $cat_id = $cats[id];
    $cat_title = strtoupper(stripslashes($cats[cat_name]));
    $cat_desc = stripslashes($cats[cat_desc]);

    $display_block .= "<tr><td width ='300' height ='50'><strong><a
    href=\"catagories.php?cat_id=$cat_id\">$cat_title</a></strong>
    $cat_desc</td></tr>";
    }

    displays
    <tr><td></td></tr>
    <tr><td></td></tr>
    <tr><td></td></tr>.....

    i want it to display like this
    <tr><td></td><td></td><td></td></tr>
    <tr><td></td><td></td><td></td></tr>
    <tr><td></td><td></td><td></td></tr>
    <tr><td></td><td></td><td></td></tr>.....
    where you display only 3 columns in a row

    Can anyone of you help me with this problem pls...
     
    white10, Jun 20, 2007 IP
  2. Vbot

    Vbot Peon

    Messages:
    107
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Change:
    $display_block .= "<tr><td width ='300' height ='50'><strong><a
    href=\"catagories.php?cat_id=$cat_id\">$cat_title</a></strong>
    $cat_desc</td></tr>";
    
    PHP:
    To:
    $display_block .= "<tr><td width ='300' height ='50'><strong><a
    href=\"catagories.php?cat_id=$cat_id\">$cat_title</a></strong>
    $cat_desc</td><td></td><td></td></tr>";
    
    PHP:
    Or:
    $display_block .= "<tr><td width ='300' height ='50' colspan='3'><strong><a
    href=\"catagories.php?cat_id=$cat_id\">$cat_title</a></strong>
    $cat_desc</td></tr>";
    
    PHP:
     
    Vbot, Jun 20, 2007 IP
  3. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #3
    Vbot, I think he wants items in those new cells ;)

    $i = 0;
    define('ITEMS_PER_ROW', 3);
    
    while ($cats = mysql_fetch_array($get_cats_res)) {
    
    $cat_id = $cats[id];
    $cat_title = strtoupper(stripslashes($cats[cat_name]));
    $cat_desc = stripslashes($cats[cat_desc]);
    
    if ($i % ITEMS_PER_ROW == 0) $display_block .= '<tr>';
    $display_block .= "<td width ='300' height ='50'><strong><a
    href=\"catagories.php?cat_id=$cat_id\">$cat_title</a></strong>
    $cat_desc</td>";
    if (++$i % ITEMS_PER_ROW == 0) $display_block .= '</tr>';
    
    }
    PHP:
     
    krt, Jun 20, 2007 IP
  4. white10

    white10 Peon

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    thanks Guys
    Vbot that code doesn't do what I want it to do but I appreciate the help. Krt thanks thats brilliant, it works like a bomb, Now why didn't I think of that lol, Thanks again guys...
     
    white10, Jun 20, 2007 IP