-1

Am creating a newsletter template that can display news in tabular form, but i want the news to be displayed in two column per row. Please check this url to see what i am talking about 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) from nl i JOIN jos_k2_categories c ON c.id=i.catid ORDER BY 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">&nbsp;</td>
        </tr>
        <?php
            if($i%2 == 0)
            {
        ?>
        <tr>
            <tr>
                <td height="34">
<font color="#FF0000" size="+2"><strong><?php echo $title; ?></strong></font>&nbsp;</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>&nbsp;</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>
4
  • 2
    What's holding you up? Too localized Commented Jun 5, 2012 at 17:54
  • 1
    1) Stop using tables, they're for data, not layout. 2) Stop using FONT statments and learn CSS. Commented Jun 5, 2012 at 17:57
  • 5
    <font> tags? in 2012? The 90's called and want their HTML back. Commented Jun 5, 2012 at 17:57
  • i know am using font tag, it will be corrected to css Commented Jun 5, 2012 at 20:26

3 Answers 3

3

This will get you most of the way there:

echo '<tr>';
$i = 0;
while(...) {
    if($i > 0 and $i % 2 == 0) {
        echo '</tr><tr>';
    }
    echo '<td>My data</td>';
    $i++;
}
echo '</tr>;
Sign up to request clarification or add additional context in comments.

2 Comments

I don't understand your question. $i will only equal one for the first cell. It will continue to grow larger after that.
i tried the code but its still the same thing am getting
0

Use rowspan and colspan html property

 <tr>
  <td>A</td>
  <td colspan="2">&nbsp;</td>
 </tr>

1 Comment

this is not the solution
0

After you do your query you can write this:

<table>
<?php
$rows = 1;
$while($news = @mysql_fetch_array($query)){
  if($rows % 2 != 0){
    echo "<tr><td>" . $news['details'] . "</td>";
  }
  else {
   echo "<td>" . $news['details'] . "</td></tr>";
  }
  $row++;
}

if($rows % 2 != 0){echo "<td>&nbsp;</td></tr>"; }
?>
</table>

With this code you create a table an initialize a variable with 1, just for checking the number of rows.

Al the end if you have 3 news, the script will complete the row and an empty cell.

1 Comment

Thanks but the code didnt work for the purpose i needed it for. The url of the website is this ipaidabribenaija.com/newsletter.php

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.