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 130833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T06:00:37+00:00 2026-05-11T06:00:37+00:00

Basically I have articles in my database and I want to alter the way

  • 0

Basically I have articles in my database and I want to alter the way the first record displays. I want the lastest (Posted) article to be the focus and the older article just to list, (see F1.com). I need to know how to get the first of my values in the array and get it to display differently but I am not sure how to do this, I can do it so all rows display the same just not how to alter the first row. I also need to know how to tell the rest of the rows to display the same afterwards im guessing you use an if statement there and before that some kind of count for the rows.


Current code:

    $result = mysql_query("SELECT * FROM dbArticle WHERE userID='".$_SESSION["**"]."' ORDER BY timestamp DESC");  while($row = mysql_fetch_array($result))   {   echo "<h2 class=\"heading1\">". $row['title'] ."</h2>";   echo "By:  ".$row['username']."  Type: ".$row['type']."  Posted: ".$row['timestamp']."    $body = $row['body'];   echo "<br/><p>";   echo substr("$body",0,260);   echo "...<span class=\"tool\"><a class=\"blue\" href=\"index.php?pageContent=readArticle&id=".$row['id']."\">Read More</a></span></p><hr/>";   } mysql_close($con); 

Ok I have taken Luke Dennis’s code and tried to test it, but I am getting this error: Warning: Invalid argument supplied for foreach() this is the line of the foreach statment. Something that has just come to mind is that I will only want 5 or so of the older articles to display. This is what I have thats creating the error:

<? $con = mysql_connect("localhost","****","***"); if (!$con)   {   die('Could not connect: ' . mysql_error());   }  mysql_select_db("******", $con);  $result = mysql_query("SELECT * FROM dbArticle ORDER BY timestamp DESC"); $first = true;     foreach($result as $row){     if($first)     {         echo"".$row['title']."";         echo"this is the headline";          $first = false;     }     else     {         echo"".$row['title']."";              } }  ?> 

Do I need to add mysql_fetch_array somewhere to set the array up?

  • 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. 2026-05-11T06:00:37+00:00Added an answer on May 11, 2026 at 6:00 am

    I would just iterate through the results and apply a css class to the first entry:

    $first = true;     while ($row = mysql_fetch_assoc($result)) {   $cssClass = '';   if ($first) {     $cssClass = 'highlight';   }   echo '<p class='' . $cssClass . ''>' . $row['text'] . '</p>';   $first = false; } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a really simple Rails app. Basically an article with comments. I want
I have a basic CMS for some news articles, basically some of my content
I basically have to do a update of a record. I have a set
We have a giant SQL Server 2005 database (75GB) which basically is just data
I have a basic CMS where a user can update a database of articles
I'm on the beginning of my Learn MVC way. Basically, I don't have big
I have many security accounts on the sql database and i want to remove/add
I have created a composite control with sample details as follows. Basically, the first
Hi I have a program which is goin to basically load news articles from
I basically have three tables, posts, images and postimages (this simply contains the ids

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.