Jump to content

Display Row (A Particular One)


Warptweet

Recommended Posts

My database organises uploads by their ID number.

Each time somebody uploads a file, it's ID number is 1 higher than the previous one.

 

How would I display the row in my database that is the SECOND highest? (Not the highest) and what about the THIRD highest? FOURTH highest? I use this code as my BASE...

 

<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("my_db", $con);

$result = mysql_query("SELECT * FROM accepted_uploads
WHERE uploadid='somenumer'");

while($row = mysql_fetch_array($result))
  {
  echo $row['FirstName'] . " " . $row['LastName'];
  echo "<br />";
  }

?>

Link to comment
Share on other sites

Display last 5:

 

$query = "SELECT * FROM tablename ORDER BY id DESC LIMIT 5";

$result = mysql_query($query) or die(mysql_error());

echo '
<table>
	<tr>
		<th>Order</th>
		<th>Name</th>
	</tr>';

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo '
	<tr>
		<td>' . $i . '</td>
		<td>' . $row['LastName'] . ', ' . $row['FirstName'] . '</td>
	</tr>';
}

echo '
</table>';

 

Change the LIMIT clause on the sql query to select different ones...for example "LIMIT 1" would get the most recent, "LIMIT 1, 1" would get the second most recent.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.