mysql - Displaying two column html table while php loop -
am creating newsletter template can display news in tabular form, want news displayed in 2 column per row. please check url see talking http://www.ipaidabribenaija.com/newsletter.php thanks.
<?php $conn = mysql_connect("localhost", "rppt", "peep") or die(mysql_error()); mysql_select_db('news', $conn) or die(mysql_error()); $query = mysql_query ("select i.nid, left(i.fulltext, 350), upper(i.title), lower(c.name) nl join jos_k2_categories c on c.id=i.catid order i.id limit 0, 16") or die ('error'); $href = "http://www.ipaidabribenaija.com/index.php"; ?> <table width="500px" align="center"> <tbody> <tr> <td width="400px" height="344px" valign="top"> <table cellspacing="5"> <tbody> <?php while(list($id, $fulltext, $title, $name)=mysql_fetch_array($query)) { $i = 0; ?> <?php $replacename = eregi_replace(" ", "-", $name); ?> <tr> <td height="34"> </td> </tr> <?php if($i%2 == 0) { ?> <tr> <tr> <td height="34"> <font color="#ff0000" size="+2"><strong><?php echo $title; ?></strong></font> </td> </tr> <tr> <td height="34"><p><?php echo $fulltext; ?>...</p> <p><a href="<?php echo $href ."/". $replacename ."/item/". $id; ?>">read more...</a></p> </td> </tr> <?php } else{ ?> <tr> <td height="34"><font color="#ff0000" size="+2"><strong><?php echo $title; ?></strong></font> </td> </tr> <tr> <td height="34"><p><?php echo $fulltext; ?>...</p> <p><a href="<?php echo $href ."/". $replacename ."/item/". $id; ?>">read more...</a></p></td> </tr> <?php } } ?> </tr> </tbody> </table> </td> </tr> </tbody> </table>
this of way there:
echo '<tr>'; $i = 0; while(...) { if($i > 0 , $i % 2 == 0) { echo '</tr><tr>'; } echo '<td>my data</td>'; $i++; } echo '</tr>;
Comments
Post a Comment