Jump to content

table row display


helpme415

Recommended Posts

Hi. I'd like a table that displays 4 images per row, in as many rows as necessary. For some reason, the code below works for the first row (it has 4 images), but then second row displays *all* of the remaining images and does not break into subsequent rows.

 

Can anyone help? This is for a wordpress site. Thank you.

 

 

 

<div id="content" class="narrowcolumn" role="main">

 

    <?php if(is_page('Cartoons')){

 

        $category_id = get_cat_ID( 'Cartoon' );

 

        $myposts = get_posts('category='.$category_id);

 

        $count = 0;

 

        ?>

 

    <div id="holder">

 

        <table id="total_table" border="0" cellspacing="0" cellpadding="0">

 

            <tr><td valign="top" class="content_width">

 

                    <h1 class="componentheading">Political Cartoons</h1>

 

                    <table border="0" cellspacing="0" cellpadding="0" style="float:left;" >

 

                        <tr><?php foreach($myposts as $post) :

 

                            setup_postdata($post);

 

                            $count +=1;

 

                            ?>

 

                            <td width="175" align="center">

 

                                <table>

 

                                    <tr>

 

                                    <td valign="middle" height="180px;">

 

                                        <div class="image_border">

 

                                            <a class="contentpagetitle" href="<?php the_permalink() ?>"><img src="<?php echo get_first_image();?>" style="max-height:180px;max-width:160px;" /></a>

 

                                        </div>

 

                                    </td>

 

                                    </tr>

 

                                    <tr>

 

                                        <td style="font-weight:normal;padding-left:5px;" class="font_12">

 

                                            <b><?php the_title(); ?></b><br/>

 

                                            From : <?php if(get_the_author_firstname())echo get_the_author_firstname(); else echo get_the_author(); ?><br/>

 

                                            Date : <?php echo the_time('m:j:Y'); ?>

 

                                        </td>

 

                                    </tr>

 

                                </table>

 

                                <div class="cl_5"></div>

 

                            </td>

 

                            <td width="5px;"></td>

 

                            <?php if($count==4){ ?>

 

                                <tr><td colspan="7"><div class="sep_line"></div>

 

                                </td><td></td></tr>

 

                        </tr>

 

                        <tr>

 

                            <?php } ?>

 

                        <?php endforeach; ?>

 

                            <td>&nbsp</td>

 

                        </tr>

 

                    </table>

 

                </td>

 

                <td class="table_left_border" valign="top">

 

                    <div class="custom_sidebar">

 

                        <?php include "custom_sidebar.php"; ?>

 

                    </div>

 

            </td></tr>

 

        </table>

 

    </div>

 

</div>

 

 

Link to comment
https://forums.phpfreaks.com/topic/197932-table-row-display/
Share on other sites

If you're trying to do a thumbnail gallery this may help you.

 

It sets up the number of columns and if there is more that the maximum left for that row it creates a new row

 

define ("NUMCOLS",5);

echo "<table border='0' id='gallery'>";

while (list($eventname,$festivalid,$image,$thumb,$description,$username) = $result->fetchrow()) {
if ($count % NUMCOLS == 0) echo "<tr>\n";  # new row
echo "<td><div class='img-shadow'><a href='image.php?id=$festivalid&festival=$eventname&pagenum=$counter'><img src='users/$username/albums/$festivalid/thumbs/$thumb' alt='$description' title='$description' style='border:none' /></a></div></td>\n";

$count++;

if ($count % NUMCOLS == 0) echo "</tr>\n";  # end row
}

# end row if not already ended

if ($count % NUMCOLS != 0) {
   while ($count++ % NUMCOLS) echo "<td> </td>";
   echo "</tr>\n";
}
echo "</table>";

Link to comment
https://forums.phpfreaks.com/topic/197932-table-row-display/#findComment-1038650
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.