Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8313245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:25:35+00:00 2026-06-08T20:25:35+00:00

New to this board but loving it so far :) I am currently helping

  • 0

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&oslash;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&aelig;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&aelig;s mere</a></div></td>');
      $i++;
      $p++;
    }
    else
    {
      $i = 0;
      $p = 0;
    }
  }
  ?>
</table>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T20:25:37+00:00Added an answer on June 8, 2026 at 8:25 pm

    may be looks better

    $result = mysql_query($query) or die("Connection Error:" . mysql_error());
    
    $items = array();
    
    while($row = mysql_fetch_assoc($result)){
       $items[] = array('date'=>$row['data'],
                        'thumbnail'=>$row['thumbnail'],
                        'headline'=>$row['headline'],);
    }
    
    $pairs = array_chunk($items,4);
    
    foreach ($pairs as $pair){
    
      print '<tr>';
    
      foreach ($pair as $row){
        print('<td><div style="padding-left:8px;"><b>Tilf&oslash;jet d. '.$row['date'].'</b></div><div class="news_thumbframe"><img src="./upload/'.$row['thumbnail'].'" alt=""/></div></td>');
      }
    
      print '<tr/><tr>';
    
      foreach ($pair as $row){
        print('<td width="215" valign="top"><br /><div style="padding-left:8px;"><h2>'.$row['headline'].'</h2><a href="#">L&aelig;s mere</a></div></td>');
    
      }  
      print '<tr/>'; 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to this technology. I searched a lot but cant find any
I'm new to this forum, but I've seen it a few times while trying
I am new on this stuff and this could be a simple question, but
I'm trying to make a message board with php, but when a new message
This is my first post here, but I'm not new to the site (call
I am new this sharepoint development and i have task in hand to do
new to this site so sorry if this question is inappropriate, or in the
New to this library (no more familiar with BeautifulSoup either, sadly), trying to do
Im new to this.I have a cron file called xml.php and i want to
Why does this: (new[]{1,2,3}).Cast<decimal>(); result in an InvalidCastException: Specified cast is not valid.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.