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
https://forums.phpfreaks.com/topic/43592-display-row-a-particular-one/
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.

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.