Jump to content

Help With Limiting The Number Of Rows A Mysql Query Displays


Recommended Posts

ok so I have a Database with a lot of Articles in it and I want only the three most recent articles to be displayed on the Home Page so heres what I got so farDatabase.php

<?php$Connection = mysql_connect("Database","UserName","Password");if (!$Connection)  {  die('Could not connect: ' . mysql_error());  }mysql_select_db("Database", $Connection);?>

Yeah for this next File I want to Limit the query results to only 3 Articles. I was Thinking there would be some code with the "While" Function but I really don't knowSo if anyone could help me with this that would be awesome THANKS :) :)Articles.php.php

<?phprequire("Database.php");$Results = mysql_query("SELECT * FROM Articles ORDER BY ArticleId DESC");mysql_close($Connection);while($Row = mysql_fetch_array($Results))	{?><div class="ArticleBoxes">	<div class="Title"><h2 align="left">	<a href="java script:void(0);"><?php echo $Row['Title']; ?></a>	</h2></div>		<span class="Date" align="left"><?php echo $Row['Date']; ?></span>	<br />	<span class="Reviewed" align="left">Reviewed By <?php echo $Row['ReviewedBy']; ?></span>		<div class="ArticleImage">	<img src="<?php echo $Row['Image']; ?>" width="150" height="136" />	</div>		<div class="ArticleBody" align="left">		<?php echo $Row['Snippet']; ?>		</div>	</div><?php	}?>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...