Jump to content

[SOLVED] Output Latest Three Records


chordsoflife

Recommended Posts

I'm having trouble figuring out how to output only the latest three records. I have it in the order I want, and I'm thinking what I'm looking for is a do while loop, but how would I write something like that? How can I store the primary key in a variable during the loop to use it in the while? Wrong approach?

 

Any help.. please  ???

Link to comment
https://forums.phpfreaks.com/topic/117104-solved-output-latest-three-records/
Share on other sites

Sure thing:

 

	   $sql = "SELECT * FROM updates ORDER BY update_id DESC;";  
		  
	   $sql_result = mysql_query($sql,$connect)  
			or die(mysql_error());

		while ($row = mysql_fetch_array($sql_result)) {  
		extract($row);
			echo "<div id=\"containerPost\">
				  <h1>" . $update_title . "</h1>
				  <h2>Posted on " . $update_date . "</h2>
				  <p>" . $update_content . "</p>
				  </div>";
		}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.