New to this board but loving it so far :)
I am currently helping a friend of mine redo her personal website and I am running my head against a wall on the logic for a table.
The table is suppossed to show the latest news in a table consisting of 4 columens/cells/TDs pr row (nothing more) - looing something like this: http://screencast.com/t/Rh39oh6ms0OL
So basically I have a SQL query that selects the date, thumbnail and headline from the news table (ordered by id desc so I get the newest first).
I have made some logic (as you can see in the code below) but it is only resulting in the first row of the table showing. Anyone out there who can get me back on the right track? It will be very much appreciated.
<table>
<?php
//PHP code used for building HTML table showing news-resumes
//Written by: Jesper Flindt
//Date: 2012.07.30
//Version: 1.0
//Getting data from MySQL database
$query = "select date, thumbnail, headline from news order by id desc";
$result = mysql_query($query) or die("Connection Error:" . mysql_error());
//Setting variables
$i = 0;
$p = 0;
//Starting row in table
print('<tr>');
//Looping through the resultset
while($row = mysql_fetch_assoc($result))
{
//Limit row to 4 cells (TDs)
if($i < 4)
{
//Display the date of the news as well as its thumbnail
print('<td><div style="padding-left:8px;"><b>Tilføjet d. '.$row['date'].'</b></div><div class="news_thumbframe"><img src="./upload/'.$row['thumbnail'].'" alt=""/></div></td>');
$i++;
$p++;
}
//If row is 4 cells wide, start new row
else if($i % 4 == 0)
{
print('</tr><tr>');
$i++;
$p++;
}
//Every second row should display the news headline as well as a "Read More" link ("Læs mere" in danish)
else if($i % 4 != 0 || $p % 4 == 0)
{
print('<td width="215" valign="top"><br /><div style="padding-left:8px;"><h2>'.$row['headline'].'</h2><a href="#">Læs mere</a></div></td>');
$i++;
$p++;
}
else
{
$i = 0;
$p = 0;
}
}
?>
</table>